Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Equivalent of VFP INLIST with string of values
Message
 
 
À
27/11/2007 23:23:17
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01271536
Message ID:
01271677
Vues:
18
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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform