Question : How to use variables in sql openquery

Hi I am grabbing some data from another server using an openquery. I want to put one where statement on it where i specify the user but i want to do it as a parameter.

I have attached a code snippet that is currently working. I want to replace testuser with a variable such as @user that i can set elsewhere however i keep getting syntax errors.

Any help on this would be greatly appreciated
1:
2:
3:
4:
SELECT     NTUserName, TBSUserName, Location
FROM         OPENQUERY(mk103s009, 
                      'Select * From TBSSuccesslog.dbo.usermapping inner join Customers.dbo.Applicationusers on UserID = TbsUserName where NTUsername =''testuser'' ')
                       AS users

Answer : How to use variables in sql openquery

You can create a unique index against the two columns. In SSMS, open up the design of your table. Right click in the design tab and select Indexes/Keys. Click the Add button and in the Columns row, either type in your columns or use the "more" button (the ellipse) to view the Index Columns window.
Random Solutions  
 
programming4us programming4us