sql server - SSIS changes OLE DB Source query parameter data type at runtime -
i want query return yesterdays records , flexible in future if there need reload x days. therefore project parameter daystoreload int32 , value set -1.
source query looks this:
select * state.vstatehourly s s.datetime >= dateadd(d, convert(int, ?), dateadd(d,0,datediff(d,0,getdate())))
this works expected in multiple environments, on 1 site results strange.
when running sql profiler have found checking data type of s.datetime column before executing above query. event before source query execution is:
set fmtonly on select s.datetime state.vstatehourly s 1=2 set fmtonly off
after ssis seems set ? parameter data type datetime, since following event in trace is:
declare @p1 int set @p1=5 exec sp_prepare @p1 output,n'@p1 datetime',n'set fmtonly off; select top 10 * state.vstatehourly s s.datetime >= dateadd(d, convert(int, @p1), dateadd(d,0,datediff(d,0,getdate())))',1 select @p1
which followed by:
exec sp_execute 1,'1899-12-29 00:00:00'
i can not observe behaviour in other environment available me.
source sql-server version: 10.50.6529.0
ssis server version: 13.0.1601
any ideas might causing data type lookup , how stabilize behaviour?
i got working moving the
dateadd(d, convert(int, ?), dateadd(d,0,datediff(d,0,getdate())))
part of statement datetime variable. variable expression looks this:
dateadd("day", @[$project::daystoreload] , dateadd("day", datediff("day",(dt_dbdate)("1900-01-01"), getdate()), (dt_dbdate)("1900-01-01")))
it using global daystoreload parameter create datetime value. mapped variable original query ended looking this:
select * state.vstatehourly s s.datetime >= ?
now sql profiler shows db engine checking type of s.datetime field , runs query compare datetime type variable. result rows starting midnight day before.
Comments
Post a Comment