Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server Variables

Status
Not open for further replies.

SQLMeToo

Technical User
Apr 10, 2000
12
0
0
AU
I need to pass the @TheVar variable to the <br>IN statement but this keep on giving me 0 records -<br>if I type the statement into the SQL <br>&quot;WHERE Name IN ('John', 'Frank', 'Tom')<br>the statement works fine, 20 records returned.<br><br>DECLARE @TheVar nvarchar(40)<br>SET @TheVar = &quot;'John', 'Frank', 'Tom'&quot;<br><br>SELECT COUNT(FieldName) <br>FROM Clients <br>WHERE Name IN (@TheVar)<br><br>Any Ideas????? - MS SQL Server 7.0 SP2<br>Regards
 
If sure this is easy to fix but I'm not near an SQL Server and I wouldn't want to give you incorrect information.&nbsp;&nbsp;You could however put the whole command into a string and then execute the string:<br><br>DECLARE @MyCommand VarChar(100)<br><br>SET @MyCommand = 'SELECT COUNT(fieldname) FROM clients WHERE Name IN (&quot;John&quot;,&quot;Frank&quot;,&quot;Tom&quot;)'<br><br>EXEC (@MyCommand)<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top