I have a MS SQL Query that is pulling data via from a remote server. The data that I\'m pulling down needs to be filtered by a date that is determined at run time.. When
Can't you just send a query like this, or does the clr function have to actually be called inside the select statement?
Declare @datetime datetime
Set @datetime = dbo.MyCustomCLRDateFunction()
SELECT * FROM SERVER.Database.dbo.RemoteView
WHERE EntryDate > @datetime
You could also construct a string and use an openquery ...
set @sqlString =
' select into myTable from openquery
(remoteServer,
"SELECT * FROM Database.dbo.RemoteView WHERE EntryDate > %DTSTART"
)
'
set @sqlString =
replace(@sqlString, '%DTSTART',
(select cast(dbo.MyCustomCLRDateFunction() as char(8))
)
EXECUTE sp_executesql @stmt=@sqlString
You need to properly decorate your CLR function to mark it as Deterministic, Precise and Data Access/System Data Access as DataAccessKind.None.