Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do inside quotes
Message
De
10/09/2013 18:32:34
 
 
À
10/09/2013 18:09:28
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01582787
Message ID:
01582792
Vues:
61
By the way, on a less important note....I've discovered recently (and a recent post by Boris reminded me), it's not necessary to use the FOR XML trick to simply generate a string of values.

Just as a simple example....using the ShipMethod table in Adventureworks....I used to do this...
declare   @ShipMethodNameList nvarchar(1000) = ''
set @ShipMethodNameList = 
      stuff (  (  select distinct ',[' +  
           cast(ShipMethodID as varchar(100))  +
               '] as [' + Name + ']'     
               from Purchasing.ShipMethod 
                        for xml path('') ), 1, 1, '')
That certainly works, but usually can be done simply by doing this...where SQL Server will concatenate the string for each row the engine encounters.
declare @otherlist varchar(8000) = ''
select @OtherList = @OtherList + '['  + cast(ShipMethodID as varchar(2)) + '] as [' + Name + '],' 
        from Purchasing.ShipMethod

set @OtherList = substring(@OtherList,1,len(@OtherList)-1)
The FOR XML PATH has great uses, but in this case it can also be done a bit easier.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform