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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Variable in Select statement

Author  Topic 

rajikrishna
Starting Member

12 Posts

Posted - 2007-01-31 : 07:15:19
I have a problem in using a variable in sql query

declare @var nvarchar(100)
SET @var = 'SMTRKBASE,SMTRFAQ,SMTRSME'
SET @var = '''' + replace(@var,',',''',''') + ''''
print @var
SELECT * FROM STSOut_Unicode WHERE FileType in
(SELECT ID FROM tblSiteMetricsFileType where TxtID in (@var))

The query is not giving me any result at all, it looks like the variable @var is not getting substituted properly.

Why is this so.
whats the correct way of using a variable in a query.

I want to avoid dynamic sql.

Kristen
Test

22859 Posts

Posted - 2007-01-31 : 07:16:38
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=CSV,Splitting%20delimited%20lists,Best%20split%20functions

in particular "WHERE IN @MyCSV"

Kristen
Go to Top of Page
   

- Advertisement -