<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Le Blog SQL Server d&#039;ElSüket &#187; CSV</title>
	<atom:link href="https://blog.developpez.com/elsuket/ptag/csv/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/elsuket</link>
	<description>Nicolas Souquet - Expert SQL Server</description>
	<lastBuildDate>Mon, 05 Apr 2021 07:32:41 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Comment passer d’une liste de valeurs séparées par des virgules à une table, et inversement ?</title>
		<link>https://blog.developpez.com/elsuket/p12576/t-sql/csv_scalaire_et_inversement</link>
		<comments>https://blog.developpez.com/elsuket/p12576/t-sql/csv_scalaire_et_inversement#comments</comments>
		<pubDate>Mon, 14 Apr 2014 04:47:40 +0000</pubDate>
		<dc:creator><![CDATA[elsuket]]></dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[concaténer]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[SQLXML]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[XQuery]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/elsuket/?p=987</guid>
		<description><![CDATA[La réponse est très courte : avec les fonctionnalités SQLXML et XQuery intégrées à SQL Server. Il est parfois utile de pouvoir générer une liste de valeurs d&#8217;une colonne, séparées par des virgules ou un autre symbole imprimable. Bien que &#8230; <a href="https://blog.developpez.com/elsuket/p12576/t-sql/csv_scalaire_et_inversement">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>La réponse est très courte : avec les fonctionnalités SQLXML et XQuery intégrées à SQL Server.<br />
<span id="more-987"></span><br />
Il est parfois utile de pouvoir générer une liste de valeurs d&rsquo;une colonne, séparées par des virgules ou un autre symbole imprimable. Bien que cela serve souvent des buts de présentation, qui n&rsquo;ont donc rien à faire avec SQL, il se trouve des cas où l&rsquo;on n&rsquo;a pas le choix. C&rsquo;est par exemple le cas avec SQL Server Reporting Services (SSRS) : en effet, cet outil efficace de création assistée de rapports permet de choisir plusieurs valeurs pour un paramètre. SSRS les transmet ensuite sous la forme d&rsquo;une chaîne de caractères, dont les valeurs sont séparées par des virgules. Lorsqu&rsquo;on requête les données avec un tel paramètre, il faut dépouiller la chaîne pour en obtenir les valeurs scalaires, intelligibles par le moteur de bases de données.</p>
<p>Voyons un premier exemple très simple de génération de liste de valeurs séparées par des virgules :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">liste_GUID</span><br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; valeur_scalaire <span style="color: #0000FF;">uniqueidentifier</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">liste_GUID</span> <span style="color: #808080;">&#40;</span>valeur_scalaire<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'30815903-5911-418B-BB56-CE0CF4981142'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'029FE2E3-E57D-4C4D-A514-2448149560F9'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'F6A73DFA-C79A-40B5-B12F-55DA66C5A158'</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'D896FB47-B5B8-4E8F-BFA1-62A65F66CB8B'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
<br />
<span style="color: #0000FF;">DECLARE</span> @s <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>;<br />
<br />
<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CUMUL <span style="color: #808080;">&#40;</span>csv<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>valeur_scalaire <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">36</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> &nbsp;<span style="color: #FF0000;">','</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> &nbsp; dbo.<span style="color: #202020;">liste_GUID</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp;XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @s <span style="color: #808080;">=</span> csv<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CUMUL<br />
<br />
<span style="color: #0000FF;">SELECT</span> @s</div></td></tr></tbody></table></div>
<p>Notons qu&rsquo;avec cet exemple, nous avons une virgule en toute fin de chaîne. On peut l’éliminer simplement en écrivant :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @s <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span>;<br />
<br />
<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CUMUL <span style="color: #808080;">&#40;</span>csv<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>valeur_scalaire <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">char</span><span style="color: #808080;">&#40;</span><span style="color: #000;">36</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> &nbsp;<span style="color: #FF0000;">','</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span> &nbsp; dbo.<span style="color: #202020;">liste_GUID</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp;XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; @s <span style="color: #808080;">=</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>csv, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>csv<span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CUMUL<br />
<br />
<span style="color: #0000FF;">SELECT</span> @s</div></td></tr></tbody></table></div>
<p>Si l&rsquo;on a besoin de réaliser cela pour un ensemble (i.e. une colonne), on utilisera l&rsquo;opérateur APPLY, ou une sous requête corrélée.<br />
Pour l&rsquo;exemple, considérons les tables suivantes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Contact<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IDContact <span style="color: #0000FF;">int</span> <span style="color: #0000FF;">IDENTITY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_Contact <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , NomContact <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> UQ_Contact__NomContact <span style="color: #0000FF;">UNIQUE</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Club<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IDClub <span style="color: #0000FF;">int</span> <span style="color: #0000FF;">IDENTITY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_Club <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , NomClub <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> UQ_Club__NomClub <span style="color: #0000FF;">UNIQUE</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> Membre<br />
<span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; IDMembre <span style="color: #0000FF;">int</span> <span style="color: #0000FF;">IDENTITY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> PK_Membre <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , IDContact <span style="color: #0000FF;">int</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> FK_Membre_IDContact <span style="color: #0000FF;">FOREIGN</span> <span style="color: #0000FF;">KEY</span><span style="color: #808080;">&#40;</span>IDContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">REFERENCES</span> Contact<span style="color: #808080;">&#40;</span>IDContact<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , IDClub <span style="color: #0000FF;">int</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">CONSTRAINT</span> FK_Membre_IDClub <span style="color: #0000FF;">FOREIGN</span> <span style="color: #0000FF;">KEY</span><span style="color: #808080;">&#40;</span>IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">REFERENCES</span> Club<span style="color: #808080;">&#40;</span>IDClub<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">CONSTRAINT</span> UQ_Membre_IDContact_IDClub <span style="color: #0000FF;">UNIQUE</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span><br />
<span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'BipBip'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Coyotte'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Titi'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Sylvestre'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Bugs Bunny'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Daffy Duck'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Contact</span> <span style="color: #808080;">&#40;</span>NomContact<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Sam Le Pirate'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SQLServer'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Oracle'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'PostGreSQL'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'MySQL'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'FireBird'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Sybase'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'DB2'</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Club</span> <span style="color: #808080;">&#40;</span>NomClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'SQLite'</span><span style="color: #808080;">&#41;</span><br />
GO<br />
&nbsp;<br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>, <span style="color: #000;">4</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">3</span>, <span style="color: #000;">6</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">4</span>, <span style="color: #000;">7</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">4</span>, <span style="color: #000;">8</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">5</span>, <span style="color: #000;">3</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">6</span>, <span style="color: #000;">5</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">6</span>, <span style="color: #000;">7</span><span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">Membre</span> <span style="color: #808080;">&#40;</span>IDContact, IDClub<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">7</span>, <span style="color: #000;">8</span><span style="color: #808080;">&#41;</span><br />
GO</div></td></tr></tbody></table></div>
<p>On obtient alors la liste des clubs desquels un contact est membre avec l&rsquo;une des requêtes suivantes :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080;">-- Avec l'opérateur APPLY</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span>, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Contact</span> <span style="color: #0000FF;">AS</span> CT<br />
<span style="color: #808080;">CROSS</span> APPLY &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL.<span style="color: #202020;">NomClub</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Club</span> <span style="color: #0000FF;">AS</span> CL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Membre</span> <span style="color: #0000FF;">AS</span> MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> MB.<span style="color: #202020;">IDClub</span> <span style="color: #808080;">=</span> CL.<span style="color: #202020;">IDClub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">IDContact</span> <span style="color: #808080;">=</span> MB.<span style="color: #202020;">IDContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> LC<span style="color: #808080;">&#40;</span>liste_club<span style="color: #808080;">&#41;</span>;<br />
<br />
<span style="color: #008080;">-- Avec une sous-requête corrélée</span><br />
<span style="color: #008080;">-- Pour éliminer la virgule en fin de chaîne, on utilise ici une expression de table commune (CTE)</span><br />
;<span style="color: #0000FF;">WITH</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CTE <span style="color: #0000FF;">AS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; CT.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL.<span style="color: #202020;">NomClub</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Club</span> <span style="color: #0000FF;">AS</span> CL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Membre</span> <span style="color: #0000FF;">AS</span> MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> MB.<span style="color: #202020;">IDClub</span> <span style="color: #808080;">=</span> CL.<span style="color: #202020;">IDClub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">IDContact</span> <span style="color: #808080;">=</span> MB.<span style="color: #202020;">IDContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">Contact</span> <span style="color: #0000FF;">AS</span> CT<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; NomContact<br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>liste_club, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>liste_club<span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; CTE;<br />
<br />
<span style="color: #008080;">-- Mais on peut se passer de la CTE en utilisant une table dérivée :</span><br />
<span style="color: #0000FF;">SELECT</span>&nbsp; LC.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span>, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>LC.<span style="color: #202020;">liste_club</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
<span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; CT.<span style="color: #202020;">NomContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , <span style="color: #808080;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SELECT</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CL.<span style="color: #202020;">NomClub</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">', '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Club</span> <span style="color: #0000FF;">AS</span> CL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span>&nbsp; &nbsp; &nbsp; dbo.<span style="color: #202020;">Membre</span> <span style="color: #0000FF;">AS</span> MB<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">ON</span> MB.<span style="color: #202020;">IDClub</span> <span style="color: #808080;">=</span> CL.<span style="color: #202020;">IDClub</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">WHERE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CT.<span style="color: #202020;">IDContact</span> <span style="color: #808080;">=</span> MB.<span style="color: #202020;">IDContact</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FOR</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XML <span style="color: #0000FF;">PATH</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">''</span><span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> liste_club<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">FROM</span>&nbsp; &nbsp; dbo.<span style="color: #202020;">Contact</span> <span style="color: #0000FF;">AS</span> CT<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> LC<span style="color: #808080;">&#40;</span>NomContact, liste_club<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>Maintenant, supposons que nous avons un rapport SSRS qui appelle une procédure stockée, et que l&rsquo;un des paramètres du rapport permet un choix multiple de valeurs. Il nous est donc nécessaire de transformer cette liste de valeurs en une table d&rsquo;une seule colonne :</p>
<div class="codecolorer-container tsql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">DECLARE</span> @s <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">max</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'30815903-5911-418B-BB56-CE0CF4981142,029FE2E3-E57D-4C4D-A514-2448149560F9,F6A73DFA-C79A-40B5-B12F-55DA66C5A158,D896FB47-B5B8-4E8F-BFA1-62A65F66CB8B'</span><br />
<br />
<span style="color: #008080;">-- On ajoute la balise v en tête et en queue de chaîne,</span><br />
<span style="color: #008080;">-- et on remplace les virgules par le doublet</span><br />
<span style="color: #0000FF;">DECLARE</span> @x xml &nbsp;<span style="color: #808080;">=</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'&lt;v&gt;'</span><span style="color: #808080;">+</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>@s, <span style="color: #FF0000;">','</span> ,<span style="color: #FF0000;">'&lt;/v&gt;&lt;v&gt;'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'&lt;/v&gt;'</span> <span style="color: #0000FF;">AS</span> &nbsp;xml<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #008080;">-- On dépouille le document XML créé en utilisant la fonction nodes()</span><br />
<span style="color: #008080;">-- du langage XQuery, intégré à SQL Server depuis sa version 2005</span><br />
<span style="color: #0000FF;">SELECT</span> vs.<span style="color: #0000FF;">value</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'.'</span>, <span style="color: #FF0000;">'uniqueidentifier'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> valeur_scalaire<br />
<span style="color: #0000FF;">FROM</span> &nbsp; @x.<span style="color: #202020;">nodes</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'/v'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> x<span style="color: #808080;">&#40;</span>vs<span style="color: #808080;">&#41;</span></div></td></tr></tbody></table></div>
<p>L&rsquo;utilisation de FOR XML PATH est de très loin la méthode qui permet de générer une liste de valeurs de façon performante. Ceci n&rsquo;en fait pas une raison pour l&rsquo;utiliser à tors et à travers, mais seulement lorsque cela est nécessaire.</p>
<p>ElSüket.</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
