Forcing a SQL Remote Query to filter remotely instead of locally

前端 未结 3 1920
野的像风
野的像风 2021-01-20 02:16

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

相关标签:
3条回答
  • 2021-01-20 02:32

    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
    
    0 讨论(0)
  • 2021-01-20 02:47

    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
    
    0 讨论(0)
  • 2021-01-20 02:49

    You need to properly decorate your CLR function to mark it as Deterministic, Precise and Data Access/System Data Access as DataAccessKind.None.

    0 讨论(0)
提交回复
热议问题