Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating a dynamic sql statement
Message
De
21/09/2001 15:50:49
 
 
À
21/09/2001 15:42:38
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00559476
Message ID:
00559480
Vues:
14
>I'm trying to create a string to be executed as a dynamic sql statment via sp_ExecuteSql. Here's what I want the string to look like:
>
>select datefield from anytable where datefield = '1900-01-01'
>
>datefield and anytable are variables, and if I try to build the string I don't know how to get the single quotes around 1900-01-01. I'm too used to using a combination of double and single quotes in VFP. how do I build my string in SQL? I'm trying to do the following:
>
>SET @SqlCommand = 'SELECT ' + @datefield + ' FROM ' + @anytable + ' WHERE ' + @datefield + ' = 1900-01-01'
>
>but of course, this results in a comparison of 1900-01-01 and not '1900-01-01'


sheesh. kick my head in. This works:

SET @Date = '1900-01-01'
SET @SqlCommand = 'SELECT ' + @datefield + ' FROM ' + @anytable + ' WHERE ' + @datefield + ' = ' + @Date
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform