Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
bhavyan_jobs
Starting Member
6 Posts |
Posted - 2002-11-21 : 06:32:21
|
| Hi There !I want to run the following pass-through query on the remote serverselect * from tableX where colA = @varZ (Query to be passed to remote server)i'm not getting able how to write the query and pass the variable @varZ in the WHERE Clause using following syntaxselect * from openquery(XYZServer, 'select * from tableX where colA = @varZ') (This is the incorrect syntax)plz suggest something so that i could lland safelyreply ASAPregardsbhavyaBhavyanidhi KukrejaNetwork Programs India Ltd.Member Technical StaffB-1-C, Sector 10Noida-201301U.P.Phone-0120-4536622 |
|
|
samsekar
Constraint Violating Yak Guru
437 Posts |
Posted - 2002-11-21 : 07:05:16
|
| select * from openquery(XYZServer, 'select * from tableX where colA = @varZ') (This is the incorrect syntax)Here @VarZ will be considered as a text not as a variable instead u can use "sp_executeSql" stored procedure. refer BOL for furthur details.Sekar |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-11-21 : 13:50:54
|
| try:select * from openquery(XYZServer, 'select * from tableX where colA = ' + @varZ)note that we are dereferencing varZ and appending its value to the string, so its VALUE is what is processed as the SQL statement.If colA is a char field, you will have to put a quote before and after it. You may need to do this in steps, by declaring a variable first and setting it. Not sure about that, though. DECLARE @VAL varchar(2000);SELECT @VAL = 'Select * tableX WHERE ColA = ' + char(39) + @varZ + CHAR(39)SELECT * FROM Openquery(XYZServer, @VAL)- Jeff |
 |
|
|
|
|
|