• OK. so this is how it is. When you hardcode a value in the query using linked server, you can find the correct filter applied at the remote server and you happily get the results.

    But when a variable gets involved which can be dynamic, it cannot be used in the linked server straightforward. The trick is to make a query first using that variable value and then pass it to the engine rather than directly using the variable in a linked server syntax. for example:

    DECLARE @sql VARCHAR(8000)

    declare @lastactivitydate nvarchar(30);

    select @lastactivitydate='2012-10-09';

    SET @sql = 'select * from Server.[Database].dbo.[vw_customers]

    where lastactivitydate= '+@lastactivitydate

    --select @sql

    EXEC(@Sql)

    You will have to use dynamic SQL here like I showed above. You will end up sometimes wondering about undefined variables, some syntax errors but they will fade away if you play with the quotes near the variable. The above case works for me because the column 'lastactivitydate' in the remote server is an integer. If that was a character value I would have played with the quotes.

    note that there is a commented line 'select @sql'

    I usually comment the execute part first and uncomment this portion to first know what statement is generated and I try to execute that individually. That helps when you get syntax errors and want to fix them.

    Try this method and let me know if this works.