Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Equivalent of VFP INLIST with string of values
Message
 
 
To
27/11/2007 23:23:17
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01271536
Message ID:
01271677
Views:
24
MS SQL Server always recognizes single quote (') as a string literal delimiter. The double quote(") is recognized as a string literal delimiter only when SET QUOTED_IDENTIFIER is OFF. It's better to use a single quote wich is independent of any settings. A single quote inside such string literals has to be doubled.
However it'll not help wit your query because SQL Server will treat @param as one value not as comma separated values for IN operator. You'll have to use dynamic sql
set @param = '''Ohio'',''Michigan'','Texas'''
SET @sql = 'SELECT * from table where cfield in (' + @param  + ')'
EXECUTE (@sql)
<snip>

>declare @param as varchar(100)
>set @param = 'Ohio','Michigan','Texas'
>I didn't know any other quotes that tsql would eat such as
>
>[ 'Ohio','Michigan','Texas' ] or
>" 'Ohio','Michigan','Texas' "
>
>so I would get the string I wanted in
>
>SELECT * from table where cfield in (@param)
>
>(not sure I explained that very clearly in my question )
>
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform