<?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>SQL - Etienne ZINZINDOHOUE &#187; SQL SERVER 2005</title>
	<atom:link href="https://blog.developpez.com/zinzineti/pcategory/sql-server-2005/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/zinzineti</link>
	<description>Bases de données</description>
	<lastBuildDate>Thu, 09 Aug 2012 13:57:35 +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>customisation : traitement de chaines de caractères</title>
		<link>https://blog.developpez.com/zinzineti/p10553/sql-server-2005/customisation_traitement_de_chaines_de_c</link>
		<comments>https://blog.developpez.com/zinzineti/p10553/sql-server-2005/customisation_traitement_de_chaines_de_c#comments</comments>
		<pubDate>Mon, 28 Nov 2011 19:32:01 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[En T-SQL la fonction SUBSTRING (c,p,n) retourne n caractères de c (à partir de la gauche) à partir de la position p. Et si je veux retourner n caractères de c à partir de la droite depuis la position ? Et si je veux retourner une sous-chaîne de c bornées entre les positions p1 et p2 ? c&#8217;est à dire une fonction du genre BETWEEN_STR (c, p1, p2) qui retournerait une sous chaine de c [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>En T-SQL la fonction SUBSTRING (c,p,n) retourne n caractères de c (à partir de la gauche) à partir de la position p. Et si je veux retourner n caractères de c à partir de la droite depuis la position ? Et si je veux retourner une sous-chaîne de c bornées entre les positions p1 et p2 ? c&rsquo;est à dire une fonction du genre BETWEEN_STR (c, p1, p2) qui retournerait une sous chaine de c compris entre les positions p1 et p2 ? <span id="more-94"></span></p>
<p><strong>1. Fonction BETWEEN_STR_LEFT </strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION BETWEEN_STR_LEFT (@str NVARCHAR (max), @start BIGINT, @end BIGINT) <br />
RETURNS NVARCHAR(max) &nbsp;<br />
AS &nbsp;<br />
BEGIN <br />
RETURN SUBSTRING(@str,@start,@end - @start +1) <br />
END</div></div>
<p><strong>Test BETWEEN_STR_LEFT </strong> :<br />
<code class="codecolorer text default"><span class="text">SELECT dbo.BETWEEN_STR_LEFT('abcdef',2,4) AS [BETWEEN_STR_LEFT] &nbsp; -- resultat bcd</span></code></p>
<p><strong>2. Fonction BETWEEN_STR_RIGHT</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION BETWEEN_STR_RIGHT (@str NVARCHAR (max),@start BIGINT,@end BIGINT) <br />
RETURNS NVARCHAR(max) &nbsp;<br />
AS &nbsp;<br />
BEGIN <br />
RETURN REVERSE(SUBSTRING(REVERSE(@str),@start,@end - @start +1)) <br />
END</div></div>
<p><strong>Test BETWEEN_STR_RIGHT  :</strong><br />
<code class="codecolorer text default"><span class="text">SELECT dbo.BETWEEN_STR_RIGHT('abcdef',2,4) AS [BETWEEN_STR_RIGHT] -- resultat cde</span></code></p>
<p><strong>3. Fonction PAT_RIGHT</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION PAT_RIGHT (@str NVARCHAR (max),@motif NVARCHAR(max)) <br />
RETURNS NVARCHAR(max) &nbsp;<br />
AS &nbsp;<br />
BEGIN <br />
RETURN RIGHT(@str,PATINDEX('%'+@motif+'%',@str)+1) <br />
END</div></div>
<p><strong>Test PAT_RIGHT :</strong><br />
<code class="codecolorer text default"><span class="text">SELECT dbo.PAT_RIGHT('abcdef','cd') AS [PAT_RIGHT] &nbsp;-- resultat 'cdef'</span></code></p>
<p><strong>4. Fonction PAT_LEFT</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION PAT_LEFT (@str NVARCHAR (max),@motif NVARCHAR(max)) <br />
RETURNS NVARCHAR(max) &nbsp;<br />
AS &nbsp;<br />
BEGIN <br />
RETURN LEFT(@str,PATINDEX('%'+@motif+'%',@str)+1) <br />
END</div></div>
<p><strong>Test PAT_LEFT:</strong><br />
<code class="codecolorer text default"><span class="text">SELECT dbo.PAT_LEFT('abcdef','cd') &nbsp;AS [PAT_LEFT] &nbsp; -- resultat 'abcd'</span></code></p>
<p>Happy Query <img src="https://blog.developpez.com/zinzineti/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley" /></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; </p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>fonction TRIM</title>
		<link>https://blog.developpez.com/zinzineti/p10552/sql-server-2005/fonction_trim</link>
		<comments>https://blog.developpez.com/zinzineti/p10552/sql-server-2005/fonction_trim#comments</comments>
		<pubDate>Mon, 28 Nov 2011 19:38:55 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Pourquoi la fonction TRIM n&#8217;est pas disponible de façon native sous SQL SERVER ? Chaque fois que je veux supprimer les espaces à gauche et à droite d&#8217;une chaîne, je fais la même acrobatie du genre LTRIM(RTIM (machaine)). Et si en plus il y a des REPLACE et des SUBSTRING à faire le code devient moins lisible &#8230; Et je demande ce que ça coûte à MS de mettre à disposition la fonction TRIM sous [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Pourquoi la fonction TRIM n&rsquo;est pas disponible de façon native sous SQL SERVER ? Chaque fois que je veux supprimer les espaces à gauche et à droite d&rsquo;une chaîne, je fais la même acrobatie du genre LTRIM(RTIM (machaine)). Et si en plus il y a des REPLACE et des SUBSTRING à faire le code devient moins lisible &#8230; Et je demande ce que ça coûte à MS de mettre à disposition la fonction TRIM sous T-SQL ?<br />
<span id="more-93"></span></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE FUNCTION TRIM (@str NVARCHAR (max)) <br />
RETURNS NVARCHAR(max) &nbsp;<br />
AS &nbsp;<br />
BEGIN <br />
RETURN RTRIM(LTRIM(@str)) <br />
END</div></div>
<p><strong>=> Test</strong><br />
<code class="codecolorer text default"><span class="text">SELECT 'Gauche ' + dbo.TRIM(' SQL SERVER ')+ ' Droite' &nbsp;--&gt; retourne 'Gauche SQL SERVER Droite'</span></code></p>
<p>Notons au passage que la fonction TRIM est disponible nativement sous ORACLE.</p>
<p>SELECT &lsquo;Gauche &lsquo; || TRIM(&lsquo; SQL SERVER &lsquo;) || &lsquo; Droite&rsquo; FROM DUAL;   &#8211;> retourne &lsquo;Gauche SQL SERVER Droite&rsquo;</p>
<p>J&rsquo;espère que MS mettra à disposition dans la version <strong> suivante de SQL SERVER 2012</strong> la fonction TRIM en standard. </p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; </p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Superviser en temps réel les applications/utilisateurs connectés</title>
		<link>https://blog.developpez.com/zinzineti/p10496/sql-server-2005/superviser_en_temps_reel_les_application</link>
		<comments>https://blog.developpez.com/zinzineti/p10496/sql-server-2005/superviser_en_temps_reel_les_application#comments</comments>
		<pubDate>Sat, 12 Nov 2011 21:47:45 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Quels sont les utilisateurs qui sont actuellement connectés à une instance de base de données ? Depuis quand sont-ils connectés ? leurs sessions sont-elles actives ? Quelles sont les applications qui sont connectées aux bases de données ? Quels comptes utilisent ces applications ? SQL Server met à disposition des procédures stockées,vues ou fonctions systèmes pour obtenir des informations sur les utilisateurs et les processus : sp_who,sp_who2,sys.dm_exec_connections,sys.sysprocesses,connectionproperty fournissent énormément d&#8217;informations pour superviser les utilisateurs et [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Quels sont les utilisateurs qui sont actuellement connectés à une instance de base de données ? Depuis quand sont-ils connectés ? leurs sessions sont-elles actives ? Quelles sont les applications qui sont connectées aux bases de données ? Quels comptes utilisent ces applications ?<br />
<span id="more-89"></span><br />
SQL Server met à disposition des procédures stockées,vues ou fonctions systèmes pour obtenir des informations sur les utilisateurs et les processus : sp_who,sp_who2,sys.dm_exec_connections,sys.sysprocesses,connectionproperty fournissent énormément d&rsquo;informations pour superviser les utilisateurs et processus. Selon le focus il y a un choix à faire parmi ces procédures stockées,vues ou fonctions sus-citées</p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font size="2"><font color="#000000"> </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">c</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">session_id</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">[session_id]</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">c</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">net_transport</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">[protocol]</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">c</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">auth_scheme</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">[authentification]</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">s</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">login_time</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">c</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">last_read</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">c</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">last_write</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">s</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">hostname</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">[client]</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">s</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">loginame</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">@@SERVERNAME</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">[server]</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">s</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">program_name</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008080" size="2"><font color="#008080" size="2">s</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">status</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font color="#000000" size="2"> </font><font color="#00ff00" size="2"><font color="#00ff00" size="2">sys</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#00ff00" size="2"><font color="#00ff00" size="2">dm_exec_connections</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">c</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">INNER</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">JOIN</font></font><font color="#000000" size="2"> </font><font color="#00ff00" size="2"><font color="#00ff00" size="2">sys</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#00ff00" size="2"><font color="#00ff00" size="2">sysprocesses</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">s</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">c</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">session_id</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">s</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008080" size="2"><font color="#008080" size="2">spid</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHERE</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">session_id</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">&lt;&gt;</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">@@SPID</font></font></span></p>
</blockquote>
<p><img src="http://zinzineti.ftp-developpez.com/images/who.jpg" alt="who" title="who" /></p>
<p>Happy Query <img src="https://blog.developpez.com/zinzineti/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley" /></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heure d&#8217;été : Daylight Saving Time (DST)</title>
		<link>https://blog.developpez.com/zinzineti/p10419/sql-server-2005/heure_d_ete_daylight_saving_time_dst</link>
		<comments>https://blog.developpez.com/zinzineti/p10419/sql-server-2005/heure_d_ete_daylight_saving_time_dst#comments</comments>
		<pubDate>Thu, 20 Oct 2011 18:49:13 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[L&#8217;heure d&#8217;été [Daylight Saving Time (DST)] ou changement d&#8217;heure d&#8217;été est un peu complexe à gérer pour les applications informatiques. Car les règles du changement d&#8217;heure varient selon les fuseaux horaires (timezones). Voici une fonction CLR qui renvoie les périodes (date-heure) de début et de fin d&#8217;été pour le fuseau horaire actuel(Current TimeZone) de l&#8217;ordinateur qui l&#8217;exécute. => Le code C# using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Globalization; using System.Collections; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>L&rsquo;heure d&rsquo;été [Daylight Saving Time (DST)] ou changement d&rsquo;heure d&rsquo;été est un peu complexe à gérer pour les applications informatiques. Car les règles du changement d&rsquo;heure varient selon les fuseaux horaires (timezones). Voici une fonction CLR qui renvoie les périodes (date-heure) de début et de fin d&rsquo;été pour le fuseau horaire actuel(Current TimeZone) de l&rsquo;ordinateur qui l&rsquo;exécute.</p>
<p><span id="more-84"></span></p>
<p><strong>=> Le code C# </strong></p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Data;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Data.SqlClient;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Data.SqlTypes;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> Microsoft.SqlServer.Server;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Globalization;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">using</font></font><font size="2"><font color="#000000"> System.Collections;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">partial</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">class</font></font><font color="#000000" size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">DST</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">{</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">[Microsoft.SqlServer.Server.</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlFunction</font></font><font size="2">(FillRowMethodName = </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;FillRow&quot;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">, TableDefinition = </font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;Year int, StartDST Datetime, EndDST Datetime&quot;</font></font><font size="2">)]</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">static</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">IEnumerable</font></font><font size="2"> F_DST(</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlInt32</font></font><font size="2"> StartYear, </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlInt32</font></font><font size="2"> EndYear)</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">{</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#2b91af" size="2"><font color="#2b91af" size="2">ArrayList</font></font><font size="2"> rowsArray = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ArrayList</font></font><font size="2">();</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">GetDST (StartYear,EndYear,rowsArray);</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">return</font></font><font size="2"> rowsArray;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">}</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">public</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">static</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">void</font></font><font size="2"> GetDST(</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlInt32</font></font><font size="2"> StartYear, </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlInt32</font></font><font size="2"> EndYear, </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">ArrayList</font></font><font size="2"> rowsArray)</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">{ </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#2b91af" size="2"><font color="#2b91af" size="2">TimeZone</font></font><font size="2"> tz = </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">TimeZone</font></font><font size="2">.CurrentTimeZone;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#2b91af" size="2"><font color="#2b91af" size="2">DaylightTime</font></font><font size="2"> daylight;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">for</font></font><font size="2"> (</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font size="2"> i = (</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font size="2">)StartYear; i &lt;= (</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font size="2">)EndYear; i++)</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">{</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">daylight = tz.GetDaylightChanges(i);</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2">[] column = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2">[3];</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">column[0] = daylight.Start.Year;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">column[1] = daylight.Start;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">column[2] = daylight.End;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">rowsArray.Add(column);</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">}</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">tz = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">null</font></font><font size="2">;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">daylight = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">null</font></font><font size="2">;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">}</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">private</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">static</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">void</font></font><font size="2"> FillRow(</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Object</font></font><font size="2"> obj, </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">out</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlInt32</font></font><font size="2"> Year, </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">out</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlDateTime</font></font><font size="2"> StartDST, </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">out</font></font><font size="2"> </font><font color="#2b91af" size="2"><font color="#2b91af" size="2">SqlDateTime</font></font><font size="2"> EndDST)</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">{</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2">[] row = (</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">object</font></font><font size="2">[])obj;</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">Year = (</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font size="2">) row[0];</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">StartDST = (</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">DateTime</font></font><font size="2">)row[1];</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">EndDST = (</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">DateTime</font></font><font size="2">)row[2];</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">}</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">};</font></span><font size="2"><span style="display: none"> </span></font></p>
</blockquote>
<p><strong>=> Prequis pour le déployement </strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC sp_configure 'clr enabled', 1 &nbsp;<br />
RECONFIGURE WITH OVERRIDE &nbsp;<br />
GO &nbsp;<br />
ALTER DATABASE MA_BASE <br />
SET TRUSTWORTHY ON; &nbsp;<br />
GO</div></div>
<p><strong>=> Déployement </strong></p>
<p>Clique droit sur le projet > propriétés > et paramétrer les différents menu jusqu&rsquo;au menu <strong>Déployer</strong></p>
<p><img src="http://zinzineti.ftp-developpez.com/images/DST/F_DST_Deploy.jpg" alt="F_DST_Deploy" title="F_DST_Deploy" /></p>
<p>Une fois le projet déployé, la fonction et l&rsquo;assembly apparaissent dans la base de données.</p>
<p><img src="http://zinzineti.ftp-developpez.com/images/DST/F_DST.jpg" alt="F_DST" title="F_DST" /></p>
<p>Exemples d&rsquo;utilisation de la fonction<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>&#8211;> <strong>Pour le fuseau horaire (GMT +01:00) Bruxelles, Copenhague, Madrid, Paris</strong> on a:<br />
<code class="codecolorer text default"><span class="text">SELECT * FROM dbo.F_DST (2011,2012)</span></code></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Year &nbsp;------ &nbsp; StartDST &nbsp; &nbsp;--------- &nbsp;EndDST <br />
2011 &nbsp;2011-03-27 02:00:00.000 &nbsp; &nbsp; &nbsp; &nbsp;2011-10-30 03:00:00.000 <br />
2012 &nbsp;2012-03-25 02:00:00.000 &nbsp; &nbsp; &nbsp; &nbsp;2012-10-28 03:00:00.000</div></div>
<p>&#8211;> <strong>Pour le fuseau horaire (GMT -05:00) Est(Canada) </strong> on a:</p>
<p><img src="http://zinzineti.ftp-developpez.com/images/DST/Fuseau_canada.jpg" alt="Fuseau_canada" title="Fuseau_canada" /></p>
<p>NB : Après le changement du fuseau horaire n&rsquo;oublier pas de redémarrer l&rsquo;instance SQL SERVER pour prendre en compte ce changement.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time Zone</title>
		<link>https://blog.developpez.com/zinzineti/p10175/sql-server-2005/time_zone</link>
		<comments>https://blog.developpez.com/zinzineti/p10175/sql-server-2005/time_zone#comments</comments>
		<pubDate>Fri, 05 Aug 2011 11:18:47 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Pour une même application utilisée dans différentes times zones, il est pratique de stocker dans la base les données datetime en UTC/GMT et de proposer en INPUT les différentes times zones afin d&#8217;afficher correctement les données selon les réalités de la zone géographique de l&#8217;utilisateur. Voici 2 pocédures P_localDateTimeToUTC et P_UTCTolocalDateTime qui permettent de jouer à ce jeu. &#8211;========================================================================================= &#8211;&#62; Description : Retourne l&#39;UTC &#224; partir de la dateheure local &#8211;&#62; Exemple d&#39;utilisation : &#8211; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Pour une même application utilisée dans différentes times zones, il est pratique de stocker dans la base les données datetime en UTC/GMT et de proposer en INPUT les différentes times zones afin d&rsquo;afficher correctement les données selon les réalités de la zone géographique de l&rsquo;utilisateur.<br />
Voici 2 pocédures P_localDateTimeToUTC et P_UTCTolocalDateTime qui permettent de jouer à ce jeu.<br />
<span id="more-77"></span></p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;=========================================================================================</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt; Description : Retourne l&#39;UTC &agrave; partir de la dateheure local</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt; Exemple d&#39;utilisation : </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; DECLARE @LocalDateTime DATETIME,@LocalDateTimeToUTC DATETIME </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; SET @LocalDateTime= GETDATE()</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; EXEC P_localDateTimeToUTC @LocalDateTime, @LocalDateTimeToUTC OUTPUT </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; SELECT @LocalDateTimeToUTC AS [LocalDateTimeToUTC],@LocalDateTime AS [LocalDateTime],GETUTCDATE()AS [UTC]</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt; Auteur : Etienne ZINZINDOHOUE</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;=========================================================================================</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">PROCEDURE</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">P_localDateTimeToUTC</font></font><font size="2"><font color="#000000"> </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008080" size="2"><font color="#008080" size="2">@LocalDateTime</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">DATETIME</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008080" size="2"><font color="#008080" size="2">@LocalDateTimeToUTC</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">DATETIME</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">OUTPUT</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font><font size="2"><font color="#000000"> </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TRY</font></font><font size="2"><font color="#000000"> </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NOCOUNT</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@UTC</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">DATETIME</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@UTC</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">GETUTCDATE</font></font><font color="#808080" size="2"><font color="#808080" size="2">()</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Conversion du LocalDateTime en UTC</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@LocalDateTimeToUTC</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">DATEADD</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">Hour</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">DATEDIFF</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">Hour</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">GETDATE</font></font><font color="#808080" size="2"><font color="#808080" size="2">(),</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">GETUTCDATE</font></font><font color="#808080" size="2"><font color="#808080" size="2">()),</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@LocalDateTime</font></font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TRY</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">CATCH</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RETURN</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;Erreur dans la procedure stockee P_localDateTimeToUTC&#39;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">CATCH</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2"><span style="display: none"> </span></font></font></font></font></span></p>
</blockquote>
<p>Et pour faire l&rsquo;inverse </p>
<blockquote>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;=========================================================================================</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt; Description : Retourne l&#39;UTC partir de la dateheure local</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt; Exemple d&#39;utilisation : </font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; DECLARE @UTCToLocalDateTime DATETIME</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; EXEC P_UTCTolocalDateTime @UTCToLocalDateTime OUTPUT </font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; SELECT @UTCToLocalDateTime AS [UTCToLocalDateTime],GETDATE()AS [HeureLocal]</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt; Auteur : Etienne ZINZINDOHOUE</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;=========================================================================================</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">PROCEDURE</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">P_UTCTolocalDateTime</font></font><font size="2"><font color="#000000"> </font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008080" size="2"><font color="#008080" size="2">@LocalDateTime</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">DATETIME</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">OUTPUT</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font><font size="2"><font color="#000000"> </font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TRY</font></font><font size="2"><font color="#000000"> </font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NOCOUNT</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@UTC</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">DATETIME</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;DECLARE @LocalDateTimeToUTC DATETIME</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@UTC</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">GETUTCDATE</font></font><font color="#808080" size="2"><font color="#808080" size="2">()</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Conversion UTC en dateheure local</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@LocalDateTime</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">DATEADD</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">Hour</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">DATEDIFF</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">Hour</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">GETUTCDATE</font></font><font color="#808080" size="2"><font color="#808080" size="2">(),</font></font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">GETDATE</font></font><font color="#808080" size="2"><font color="#808080" size="2">()),</font></font><font color="#000000" size="2"> </font><font color="#008080" size="2"><font color="#008080" size="2">@UTC</font></font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TRY</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">CATCH</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RETURN</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;Erreur dans la procedure stockee P_UTCTolocalDateTime&#39;</font></font></font></font></p>
<p>
	<font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">CATCH</font></font></font></font></p>
</blockquote>
<p>Pour proposer à l&rsquo;utilisateur de choisir son time zone on peut charger une table TimeZone (TZ) avec les données ci-dessous noter que le séparateur est ;</p>
<blockquote><p>
TZName;StandardTime<br />
Antarctica/Vostok;UTC+00<br />
Africa/Ouagadougou;UTC+00<br />
Africa/Abidjan;UTC+00<br />
Africa/El_Aaiun;UTC+00<br />
Atlantic/Canary;UTC+00<br />
Atlantic/Faroe;UTC+00<br />
Europe/London;UTC+00<br />
Europe/Guernsey;UTC+00<br />
Africa/Accra;UTC+00<br />
America/Danmarkshavn;UTC+00<br />
Africa/Banjul;UTC+00<br />
Africa/Conakry;UTC+00<br />
Africa/Bissau;UTC+00<br />
Europe/Dublin;UTC+00<br />
Europe/Isle_of_Man;UTC+00<br />
Atlantic/Reykjavik;UTC+00<br />
Europe/Jersey;UTC+00<br />
Africa/Monrovia;UTC+00<br />
Africa/Casablanca;UTC+00<br />
Africa/Bamako;UTC+00<br />
Africa/Nouakchott;UTC+00<br />
Europe/Lisbon;UTC+00<br />
Atlantic/Madeira;UTC+00<br />
Atlantic/St_Helena;UTC+00<br />
Africa/Freetown;UTC+00<br />
Africa/Dakar;UTC+00<br />
Africa/Sao_Tome;UTC+00<br />
Africa/Lome;UTC+00<br />
Europe/Andorra;UTC+01<br />
Europe/Tirane;UTC+01<br />
Africa/Luanda;UTC+01<br />
Europe/Vienna;UTC+01<br />
Europe/Sarajevo;UTC+01<br />
Europe/Brussels;UTC+01<br />
Africa/Porto-Novo;UTC+01<br />
Africa/Kinshasa;UTC+01<br />
Africa/Bangui;UTC+01<br />
Africa/Brazzaville;UTC+01<br />
Europe/Zurich;UTC+01<br />
Africa/Douala;UTC+01<br />
Europe/Prague;UTC+01<br />
Europe/Berlin;UTC+01<br />
Europe/Copenhagen;UTC+01<br />
Africa/Algiers;UTC+01<br />
Europe/Madrid;UTC+01<br />
Africa/Ceuta;UTC+01<br />
Europe/Paris;UTC+01<br />
Africa/Libreville;UTC+01<br />
Europe/Gibraltar;UTC+01<br />
Africa/Malabo;UTC+01<br />
Europe/Zagreb;UTC+01<br />
Europe/Budapest;UTC+01<br />
Europe/Rome;UTC+01<br />
Europe/Vaduz;UTC+01<br />
Europe/Luxembourg;UTC+01<br />
Europe/Monaco;UTC+01<br />
Europe/Podgorica;UTC+01<br />
Europe/Skopje;UTC+01<br />
Europe/Malta;UTC+01<br />
Africa/Windhoek;UTC+01<br />
Africa/Niamey;UTC+01<br />
Africa/Lagos;UTC+01<br />
Europe/Amsterdam;UTC+01<br />
Europe/Oslo;UTC+01<br />
Europe/Warsaw;UTC+01<br />
Europe/Belgrade;UTC+01<br />
Europe/Stockholm;UTC+01<br />
Europe/Ljubljana;UTC+01<br />
Arctic/Longyearbyen;UTC+01<br />
Europe/Bratislava;UTC+01<br />
Europe/San_Marino;UTC+01<br />
Africa/Ndjamena;UTC+01<br />
Africa/Tunis;UTC+01<br />
Europe/Vatican;UTC+01<br />
Europe/Mariehamn;UTC+02<br />
Europe/Sofia;UTC+02<br />
Africa/Bujumbura;UTC+02<br />
Africa/Gaborone;UTC+02<br />
Europe/Minsk;UTC+02<br />
Africa/Lubumbashi;UTC+02<br />
Asia/Nicosia;UTC+02<br />
Europe/Tallinn;UTC+02<br />
Africa/Cairo;UTC+02<br />
Europe/Helsinki;UTC+02<br />
Europe/Athens;UTC+02<br />
Asia/Jerusalem;UTC+02<br />
Asia/Amman;UTC+02<br />
Asia/Beirut;UTC+02<br />
Africa/Maseru;UTC+02<br />
Europe/Vilnius;UTC+02<br />
Europe/Riga;UTC+02<br />
Africa/Tripoli;UTC+02<br />
Europe/Chisinau;UTC+02<br />
Africa/Blantyre;UTC+02<br />
Africa/Maputo;UTC+02<br />
Asia/Gaza;UTC+02<br />
Europe/Bucharest;UTC+02<br />
Africa/Kigali;UTC+02<br />
Asia/Damascus;UTC+02<br />
Africa/Mbabane;UTC+02<br />
Europe/Istanbul;UTC+02<br />
Europe/Kiev;UTC+02<br />
Europe/Uzhgorod;UTC+02<br />
Europe/Zaporozhye;UTC+02<br />
Europe/Simferopol;UTC+02<br />
Africa/Johannesburg;UTC+02<br />
Africa/Lusaka;UTC+02<br />
Africa/Harare;UTC+02<br />
Antarctica/Syowa;UTC+03<br />
Asia/Bahrain;UTC+03<br />
Africa/Djibouti;UTC+03<br />
Africa/Asmara;UTC+03<br />
Africa/Addis_Ababa;UTC+03<br />
Asia/Baghdad;UTC+03<br />
Africa/Nairobi;UTC+03<br />
Indian/Comoro;UTC+03<br />
Asia/Kuwait;UTC+03<br />
Indian/Antananarivo;UTC+03<br />
Asia/Qatar;UTC+03<br />
Europe/Kaliningrad;UTC+03<br />
Asia/Riyadh;UTC+03<br />
Africa/Khartoum;UTC+03<br />
Africa/Mogadishu;UTC+03<br />
Africa/Dar_es_Salaam;UTC+03<br />
Africa/Kampala;UTC+03<br />
Asia/Aden;UTC+03<br />
Indian/Mayotte;UTC+03<br />
Asia/Tehran;UTC+03:30<br />
Asia/Dubai;UTC+04<br />
Asia/Yerevan;UTC+04<br />
Asia/Baku;UTC+04<br />
Asia/Tbilisi;UTC+04<br />
Indian/Mauritius;UTC+04<br />
Asia/Muscat;UTC+04<br />
Indian/Reunion;UTC+04<br />
Europe/Moscow;UTC+04<br />
Europe/Volgograd;UTC+04<br />
Europe/Samara;UTC+04<br />
Indian/Mahe;UTC+04<br />
Asia/Kabul;UTC+04:30<br />
Asia/Aqtobe;UTC+05<br />
Asia/Aqtau;UTC+05<br />
Asia/Oral;UTC+05<br />
Indian/Maldives;UTC+05<br />
Indian/Kerguelen;UTC+05<br />
Asia/Dushanbe;UTC+05<br />
Asia/Ashgabat;UTC+05<br />
Asia/Samarkand;UTC+05<br />
Asia/Tashkent;UTC+05<br />
Asia/Kolkata;UTC+05:30<br />
Asia/Colombo;UTC+05:30<br />
Asia/Kathmandu;UTC+05:45<br />
Antarctica/Mawson;UTC+06<br />
Asia/Dhaka;UTC+06<br />
Asia/Thimphu;UTC+06<br />
Indian/Chagos;UTC+06<br />
Asia/Bishkek;UTC+06<br />
Asia/Almaty;UTC+06<br />
Asia/Qyzylorda;UTC+06<br />
Asia/Karachi;UTC+06<br />
Asia/Yekaterinburg;UTC+06<br />
Indian/Cocos;UTC+06:30<br />
Asia/Rangoon;UTC+06:30<br />
Antarctica/Davis;UTC+07<br />
Indian/Christmas;UTC+07<br />
Asia/Jakarta;UTC+07<br />
Asia/Pontianak;UTC+07<br />
Asia/Phnom_Penh;UTC+07<br />
Asia/Vientiane;UTC+07<br />
Asia/Hovd;UTC+07<br />
Asia/Omsk;UTC+07<br />
Asia/Novosibirsk;UTC+07<br />
Asia/Novokuznetsk;UTC+07<br />
Asia/Bangkok;UTC+07<br />
Asia/Ho_Chi_Minh;UTC+07<br />
Antarctica/Casey;UTC+08<br />
Australia/Perth;UTC+08<br />
Asia/Brunei;UTC+08<br />
Asia/Shanghai;UTC+08<br />
Asia/Harbin;UTC+08<br />
Asia/Chongqing;UTC+08<br />
Asia/Urumqi;UTC+08<br />
Asia/Kashgar;UTC+08<br />
Asia/Hong_Kong;UTC+08<br />
Asia/Makassar;UTC+08<br />
Asia/Ulaanbaatar;UTC+08<br />
Asia/Choibalsan;UTC+08<br />
Asia/Macau;UTC+08<br />
Asia/Kuala_Lumpur;UTC+08<br />
Asia/Kuching;UTC+08<br />
Asia/Manila;UTC+08<br />
Asia/Krasnoyarsk;UTC+08<br />
Asia/Singapore;UTC+08<br />
Asia/Taipei;UTC+08<br />
Australia/Eucla;UTC+08:45<br />
Asia/Jayapura;UTC+09<br />
Asia/Tokyo;UTC+09<br />
Asia/Pyongyang;UTC+09<br />
Asia/Seoul;UTC+09<br />
Pacific/Palau;UTC+09<br />
Asia/Irkutsk;UTC+09<br />
Asia/Dili;UTC+09<br />
Australia/Broken_Hill;UTC+09:30<br />
Australia/Adelaide;UTC+09:30<br />
Australia/Darwin;UTC+09:30<br />
Antarctica/DumontDUrville;UTC+10<br />
Australia/Hobart;UTC+10<br />
Australia/Currie;UTC+10<br />
Australia/Melbourne;UTC+10<br />
Australia/Sydney;UTC+10<br />
Australia/Brisbane;UTC+10<br />
Australia/Lindeman;UTC+10<br />
Pacific/Truk;UTC+10<br />
Pacific/Guam;UTC+10<br />
Pacific/Saipan;UTC+10<br />
Pacific/Port_Moresby;UTC+10<br />
Asia/Yakutsk;UTC+10<br />
Australia/Lord_Howe;UTC+10:30<br />
Pacific/Ponape;UTC+11<br />
Pacific/Kosrae;UTC+11<br />
Pacific/Noumea;UTC+11<br />
Asia/Vladivostok;UTC+11<br />
Asia/Sakhalin;UTC+11<br />
Pacific/Guadalcanal;UTC+11<br />
Pacific/Efate;UTC+11<br />
Pacific/Norfolk;UTC+11:30<br />
Antarctica/McMurdo;UTC+12<br />
Antarctica/South_Pole;UTC+12<br />
Pacific/Fiji;UTC+12<br />
Pacific/Tarawa;UTC+12<br />
Pacific/Majuro;UTC+12<br />
Pacific/Kwajalein;UTC+12<br />
Pacific/Nauru;UTC+12<br />
Pacific/Auckland;UTC+12<br />
Asia/Magadan;UTC+12<br />
Asia/Kamchatka;UTC+12<br />
Asia/Anadyr;UTC+12<br />
Pacific/Funafuti;UTC+12<br />
Pacific/Wake;UTC+12<br />
Pacific/Wallis;UTC+12<br />
Pacific/Chatham;UTC+12:45<br />
Pacific/Enderbury;UTC+13<br />
Pacific/Tongatapu;UTC+13<br />
Pacific/Kiritimati;UTC+14<br />
Atlantic/Cape_Verde;UTC-01<br />
America/Scoresbysund;UTC-01<br />
Atlantic/Azores;UTC-01<br />
America/Noronha;UTC-02<br />
Atlantic/South_Georgia;UTC-02<br />
Antarctica/Rothera;UTC-03<br />
America/Argentina/Buenos_Aires;UTC-03<br />
America/Argentina/Cordoba;UTC-03<br />
America/Argentina/Salta;UTC-03<br />
America/Argentina/Jujuy;UTC-03<br />
America/Argentina/Tucuman;UTC-03<br />
America/Argentina/Catamarca;UTC-03<br />
America/Argentina/La_Rioja;UTC-03<br />
America/Argentina/San_Juan;UTC-03<br />
America/Argentina/Mendoza;UTC-03<br />
America/Argentina/Rio_Gallegos;UTC-03<br />
America/Argentina/Ushuaia;UTC-03<br />
America/Belem;UTC-03<br />
America/Fortaleza;UTC-03<br />
America/Recife;UTC-03<br />
America/Araguaina;UTC-03<br />
America/Maceio;UTC-03<br />
America/Bahia;UTC-03<br />
America/Sao_Paulo;UTC-03<br />
America/Santarem;UTC-03<br />
America/Cayenne;UTC-03<br />
America/Godthab;UTC-03<br />
America/Miquelon;UTC-03<br />
America/Paramaribo;UTC-03<br />
America/Montevideo;UTC-03<br />
America/St_Johns;UTC-03:30<br />
America/Antigua;UTC-04<br />
America/Anguilla;UTC-04<br />
America/Curacao;UTC-04<br />
Antarctica/Palmer;UTC-04<br />
America/Argentina/San_Luis;UTC-04<br />
America/Aruba;UTC-04<br />
America/Barbados;UTC-04<br />
America/St_Barthelemy;UTC-04<br />
Atlantic/Bermuda;UTC-04<br />
America/La_Paz;UTC-04<br />
America/Campo_Grande;UTC-04<br />
America/Cuiaba;UTC-04<br />
America/Porto_Velho;UTC-04<br />
America/Boa_Vista;UTC-04<br />
America/Manaus;UTC-04<br />
America/Eirunepe;UTC-04<br />
America/Rio_Branco;UTC-04<br />
America/Halifax;UTC-04<br />
America/Glace_Bay;UTC-04<br />
America/Moncton;UTC-04<br />
America/Goose_Bay;UTC-04<br />
America/Blanc-Sablon;UTC-04<br />
America/Santiago;UTC-04<br />
America/Dominica;UTC-04<br />
America/Santo_Domingo;UTC-04<br />
Atlantic/Stanley;UTC-04<br />
America/Grenada;UTC-04<br />
America/Thule;UTC-04<br />
America/Guadeloupe;UTC-04<br />
America/Guyana;UTC-04<br />
America/St_Kitts;UTC-04<br />
America/St_Lucia;UTC-04<br />
America/Marigot;UTC-04<br />
America/Martinique;UTC-04<br />
America/Montserrat;UTC-04<br />
America/Puerto_Rico;UTC-04<br />
America/Asuncion;UTC-04<br />
America/Port_of_Spain;UTC-04<br />
America/St_Vincent;UTC-04<br />
America/Tortola;UTC-04<br />
America/St_Thomas;UTC-04<br />
America/Caracas;UTC-04:30<br />
America/Nassau;UTC-05<br />
America/Montreal;UTC-05<br />
America/Toronto;UTC-05<br />
America/Nipigon;UTC-05<br />
America/Thunder_Bay;UTC-05<br />
America/Iqaluit;UTC-05<br />
America/Pangnirtung;UTC-05<br />
America/Resolute;UTC-05<br />
America/Atikokan;UTC-05<br />
America/Bogota;UTC-05<br />
America/Havana;UTC-05<br />
America/Guayaquil;UTC-05<br />
America/Port-au-Prince;UTC-05<br />
America/Jamaica;UTC-05<br />
America/Cayman;UTC-05<br />
America/Panama;UTC-05<br />
America/Lima;UTC-05<br />
America/Grand_Turk;UTC-05<br />
America/New_York;UTC-05<br />
America/Detroit;UTC-05<br />
America/Kentucky/Louisville;UTC-05<br />
America/Kentucky/Monticello;UTC-05<br />
America/Indiana/Indianapolis;UTC-05<br />
America/Indiana/Vincennes;UTC-05<br />
America/Indiana/Winamac;UTC-05<br />
America/Indiana/Marengo;UTC-05<br />
America/Indiana/Petersburg;UTC-05<br />
America/Indiana/Vevay;UTC-05<br />
America/Belize;UTC-06<br />
America/Rankin_Inlet;UTC-06<br />
America/Winnipeg;UTC-06<br />
America/Rainy_River;UTC-06<br />
America/Regina;UTC-06<br />
America/Swift_Current;UTC-06<br />
Pacific/Easter;UTC-06<br />
America/Costa_Rica;UTC-06<br />
Pacific/Galapagos;UTC-06<br />
America/Guatemala;UTC-06<br />
America/Tegucigalpa;UTC-06<br />
America/Mexico_City;UTC-06<br />
America/Cancun;UTC-06<br />
America/Merida;UTC-06<br />
America/Monterrey;UTC-06<br />
America/Matamoros;UTC-06<br />
America/Managua;UTC-06<br />
America/El_Salvador;UTC-06<br />
America/Chicago;UTC-06<br />
America/Indiana/Tell_City;UTC-06<br />
America/Indiana/Knox;UTC-06<br />
America/Menominee;UTC-06<br />
America/North_Dakota/Center;UTC-06<br />
America/North_Dakota/New_Salem;UTC-06<br />
America/Edmonton;UTC-07<br />
America/Cambridge_Bay;UTC-07<br />
America/Yellowknife;UTC-07<br />
America/Inuvik;UTC-07<br />
America/Dawson_Creek;UTC-07<br />
America/Mazatlan;UTC-07<br />
America/Chihuahua;UTC-07<br />
America/Ojinaga;UTC-07<br />
America/Hermosillo;UTC-07<br />
America/Denver;UTC-07<br />
America/Boise;UTC-07<br />
America/Shiprock;UTC-07<br />
America/Phoenix;UTC-07<br />
America/Vancouver;UTC-08<br />
America/Whitehorse;UTC-08<br />
America/Dawson;UTC-08<br />
America/Tijuana;UTC-08<br />
America/Santa_Isabel;UTC-08<br />
Pacific/Pitcairn;UTC-08<br />
America/Los_Angeles;UTC-08<br />
Pacific/Gambier;UTC-09<br />
America/Anchorage;UTC-09<br />
America/Juneau;UTC-09<br />
America/Yakutat;UTC-09<br />
America/Nome;UTC-09<br />
Pacific/Marquesas;UTC-09:30<br />
Pacific/Rarotonga;UTC-10<br />
Pacific/Tahiti;UTC-10<br />
Pacific/Fakaofo;UTC-10<br />
Pacific/Johnston;UTC-10<br />
America/Adak;UTC-10<br />
Pacific/Honolulu;UTC-10<br />
Pacific/Pago_Pago;UTC-11<br />
Pacific/Niue;UTC-11<br />
Pacific/Midway;UTC-11<br />
Pacific/Apia;UTC-11</p>
</blockquote>
<p>Une façon simple d&rsquo;obetnir l&rsquo;heure locale actuelle et le décalage avec UTC</p>
<blockquote>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT SYSDATETIMEOFFSET() AS 'Heure locale + décalage par rapport à UTC' <br />
,SYSUTCDATETIME() AS 'UTC'</div></div>
</blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Import de données &#8211; BULK INSERT</title>
		<link>https://blog.developpez.com/zinzineti/p9697/sql-server-2005/import_de_donnees_bulk_insert</link>
		<comments>https://blog.developpez.com/zinzineti/p9697/sql-server-2005/import_de_donnees_bulk_insert#comments</comments>
		<pubDate>Fri, 21 Jan 2011 18:16:57 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Une procédure d&#8217;import de fichier de données dans une table &#8211;> Nouvelle version de la procédure /*================================================================================================ &#8211;Description : Import de fichier (.csv par exemple) dans une table &#224; l&#39;aide de BULK INSERT &#8211;Note : la table de destination &#224; m&#234;me nombre de colonnes que le fichier &#224; importer et dans le m&#234;me ordre ! &#8211; Si le nombre de colonnes dans le fichier est diff&#233;rent du celui de la table de destination, il est [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Une procédure d&rsquo;import de fichier de données dans une table<br />
<span id="more-67"></span><br />
&#8211;> Nouvelle version de la procédure</p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">/*================================================================================================</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Description : Import de fichier (.csv par exemple) dans une table &agrave; l&#39;aide de BULK INSERT</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Note : la table de destination &agrave; m&ecirc;me nombre de colonnes que le fichier &agrave; importer et dans le m&ecirc;me ordre !</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;       Si le nombre de colonnes dans le fichier est diff&eacute;rent du celui de la table de destination, il est possible</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;       d&#39;utiliser une table interm&eacute;diaire (temporaire) avant le chargement dans la table destination</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Mise jour le 11/10/2011</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Auteur : Etienne ZINZINDOHOUE</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Exemple d&#39;utilisation : </font></font><font color="#008000" size="2"><font color="#008000" size="2">EXEC P_Import_File_to_Table N&#39;E:\test.csv&#39;, N&#39;MaBase.dbo.testbulk&#39;, N&#39;,&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">================================================================================================*/</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">PROCEDURE</font></font><font size="2"><font color="#000000"> P_Import_File_to_Table</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@EmplacementFichier </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nvarchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">255</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font><font size="2"> @BaseSchemaTableName </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nvarchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">255</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font><font size="2">@separateur </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">1</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NOCOUNT</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; V&eacute;rifier l&#39;existence du fichier &agrave; importer</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font color="#000000" size="2"> @FileOK </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">INT</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">@TableOK </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">INT</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">@BULK </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">max</font></font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">EXEC</font></font><font color="#000000" size="2"> xp_fileexist @EmplacementFichier</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> @FileOK </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">OUTPUT</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">IF</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">@FileOK </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> 0</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;Le fichier importer &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @EmplacementFichier </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; n&#39;&#39;existe pas !&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RETURN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; V&eacute;rifier la pr&eacute;sence de la table de destination</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> @TableOK </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">COUNT</font></font><font color="#808080" size="2"><font color="#808080" size="2">(*)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font color="#000000" size="2"> </font><font color="#008000" size="2"><font color="#008000" size="2">INFORMATION_SCHEMA.TABLES</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHERE</font></font><font color="#000000" size="2"> TABLE_CATALOG </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;.&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> TABLE_SCHEMA </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;.&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2">TABLE_NAME </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"><font color="#000000"> @BaseSchemaTableName</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">IF</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">@TableOK </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> 0</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;La table de destination &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @BaseSchemaTableName </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; n&#39;&#39;existe pas !&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RETURN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2">&#8211;Import des donn&eacute;es</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @BULK </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> N</font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;BULK INSERT &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @BaseSchemaTableName </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; FROM &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&#39;&#39;&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @EmplacementFichier </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&#39;&#39;&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; WITH (FIELDTERMINATOR = &#39;&#39;&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2">@separateur</font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&#39;&#39;, ROWTERMINATOR = &#39;&#39;\n&#39;&#39;, FIRSTROW = 1)&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;SELECT @BULK</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">EXEC</font></font><font color="#000000" size="2"> </font><font color="#800000" size="2"><font color="#800000" size="2">sp_executesql</font></font><font size="2"><font color="#000000"> @BULK</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END<span style="display: none"> </span></font></font></span></p>
</p>
</blockquote>
<p>&#8211;> L&rsquo;ancienne version de la procédure </p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">/*================================================================================================</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Description : Import de fichier (.csv par exemple) dans une table l&#39;aide de BULK INSERT</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Auteur : Etienne ZINZINDOHOUE</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Exemple d&rsquo;utilisation :</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">EXEC P_Import_File_to_Table N&#39;E:\test.csv&#39;, N&#39;MaBase.dbo.testbulk&#39;, N&#39;,&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">================================================================================================*/</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">PROCEDURE</font></font><font size="2"><font color="#000000"> P_Import_File_to_Table</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@EmplacementFichier </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nvarchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">255</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font><font size="2"> @BaseSchemaTableName </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nvarchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">255</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font><font size="2">@separateur </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">1</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NOCOUNT</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Vérifier l&#39;existence du fichier à importer</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font size="2"> @ErreurTable </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">VARCHAR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">255</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font size="2"> @T_file_exists </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TABLE</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">(</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">file_exists </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">bit</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> file_is_a_directory </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">bit</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> parent_directory_exists </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">bit</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"> </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">INSERT</font></font><font size="2"> @T_file_exists</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">EXEC</font></font><font size="2"> </font><font color="#800000" size="2"><font color="#800000" size="2">xp_fileexist</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> </font></font><font size="2">@EmplacementFichier</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">IF</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">EXISTS</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">(</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font size="2"> file_exists</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font size="2"> @T_file_exists</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHERE</font></font><font size="2"> file_exists </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> 0</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RAISERROR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;Le fichier &quot;%s&quot; n&#39;&#39;existe pas. Vérifier d&#39;&#39;abord l&#39;&#39;existence du fichier que vous voulez importer.&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> 16</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> 1</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> @EmplacementFichier</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RETURN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Vérifier la présence de la table de destination </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">IF</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">EXISTS</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">(</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">COUNT</font></font><font color="#808080" size="2"><font color="#808080" size="2">(*)</font></font><font size="2"> </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font size="2"> </font><font color="#008000" size="2"><font color="#008000" size="2">INFORMATION_SCHEMA</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#008000" size="2"><font color="#008000" size="2">TABLES</font></font><font size="2"> </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHERE</font></font><font size="2"> TABLE_CATALOG </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;.&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> TABLE_SCHEMA </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;.&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2">TABLE_NAME </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> @BaseSchemaTableName</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">HAVING</font></font><font size="2"> </font><font color="#ff00ff" size="2"><font color="#ff00ff" size="2">COUNT</font></font><font color="#808080" size="2"><font color="#808080" size="2">(*)</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> 0</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font size="2"> @ErreurTable </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;La table &#39;</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> @BaseSchemaTableName </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; n&#39;&#39;existe pas !&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RAISERROR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">@ErreurTable</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> 16</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> 1</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> @BaseSchemaTableName</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RETURN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font size="2"> @bulk </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nvarchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">1024</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font size="2"> @bulk </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">N&#39;BULK INSERT &#39;</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> @BaseSchemaTableName </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; FROM &#39;</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&#39;&#39;&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> @EmplacementFichier </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&#39;&#39;&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; WITH (FIELDTERMINATOR = &#39;&#39;&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font size="2">@separateur</font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&#39;&#39;, ROWTERMINATOR = &#39;&#39;\n&#39;&#39;, FIRSTROW = 1)&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;PRINT @bulk</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">EXEC</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">@bulk</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END<span style="display: none"> </span></font></font></span></p>
</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2005 SP 4 : Impossible de créer un job SQL via IHM de création de job</title>
		<link>https://blog.developpez.com/zinzineti/p10380/sql-server-2005/sql_server_2005_sp_4_impossible_de_creer</link>
		<comments>https://blog.developpez.com/zinzineti/p10380/sql-server-2005/sql_server_2005_sp_4_impossible_de_creer#comments</comments>
		<pubDate>Mon, 10 Oct 2011 11:57:39 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Je pensais créer un job SQL via l&#8217;IHM de création de job sous SSMS (SQL Server Management Studio) mais à ma grande surprise il était impossible de le faire. Voici le besoin : Créer un job SQL qui exécute une procédure stockée toutes les 30 secondes. Le problème provient du fait que sous SQL SERVER 2005 SP4, l&#8217;IHM de création du job SQL ne permet pas de sélectionner le délai de rafraîchissement en secondes (toutes [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Je pensais créer un job SQL via l&rsquo;IHM de création de job sous SSMS (SQL Server Management Studio) mais à ma grande surprise il était impossible de le faire. Voici le besoin : <strong>Créer un job SQL qui exécute une procédure stockée toutes les 30 secondes.</strong><br />
<span id="more-52"></span><br />
Le problème provient du fait que sous SQL SERVER 2005 SP4, l&rsquo;IHM de création du job SQL ne permet pas de sélectionner le délai de rafraîchissement en secondes (toutes les 30 secondes).</p>
<p><img src="http://zinzineti.ftp-developpez.com/images/sqlserver2005/Planif_job.jpg" alt="job" title="job" /></p>
<p>Quelle est la version du serveur SQL ?</p>
<p><img src="http://zinzineti.ftp-developpez.com/images/sqlserver2005/version_sqlserver.jpg" alt="version serveur" title="version serveur" /></p>
<p>=> <strong>Solution de contournement</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE [msdb] <br />
GO <br />
DECLARE @jobId BINARY(16) <br />
EXEC &nbsp;msdb.dbo.sp_add_job @job_name=N'JOB_STAT_AGENTS_APPELS', &nbsp;<br />
&nbsp; &nbsp; @enabled=1, &nbsp;<br />
&nbsp; &nbsp; @notify_level_eventlog=0, &nbsp;<br />
&nbsp; &nbsp; @notify_level_email=2, &nbsp;<br />
&nbsp; &nbsp; @notify_level_netsend=2, &nbsp;<br />
&nbsp; &nbsp; @notify_level_page=2, &nbsp;<br />
&nbsp; &nbsp; @delete_level=0, &nbsp;<br />
&nbsp; &nbsp; @description=N'Procédure des statistiques des appels. Cette procédure est lancée toutes les 30 secondes', &nbsp;<br />
&nbsp; &nbsp; @category_name=N'[Uncategorized (Local)]', <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; --&gt; Proprietaire du JOB &nbsp;<br />
&nbsp; &nbsp; @owner_login_name=N'mylogin', @job_id = @jobId OUTPUT <br />
select @jobId <br />
GO <br />
&nbsp; &nbsp; &nbsp; &nbsp; --&gt; &nbsp;Affecter à @server_name le nom du serveur &nbsp;<br />
EXEC msdb.dbo.sp_add_jobserver @job_name=N'JOB_STAT_AGENTS_APPELS', @server_name = N'NomDuServeur' <br />
GO <br />
USE [msdb] <br />
GO <br />
&nbsp; &nbsp; --&gt; &nbsp;Etapes <br />
EXEC msdb.dbo.sp_add_jobstep @job_name=N'JOB_STAT_AGENTS_APPELS', @step_name=N'Statistiques appels', &nbsp;<br />
&nbsp; &nbsp; @step_id=1, &nbsp;<br />
&nbsp; &nbsp; @cmdexec_success_code=0, &nbsp;<br />
&nbsp; &nbsp; @on_success_action=1, &nbsp;<br />
&nbsp; &nbsp; @on_fail_action=2, &nbsp;<br />
&nbsp; &nbsp; @retry_attempts=0, &nbsp;<br />
&nbsp; &nbsp; @retry_interval=0, &nbsp;<br />
&nbsp; &nbsp; @os_run_priority=0, @subsystem=N'TSQL', &nbsp;<br />
&nbsp; &nbsp; @command=N'EXEC dbo.myProcedure', <br />
&nbsp; &nbsp; --&gt; Nom de la base de données &nbsp;<br />
&nbsp; &nbsp; @database_name=N'MaBase', &nbsp;<br />
&nbsp; &nbsp; @flags=0 <br />
GO <br />
USE [msdb] <br />
GO <br />
EXEC msdb.dbo.sp_update_job @job_name=N'JOB_STAT_AGENTS_APPELS', &nbsp;<br />
&nbsp; &nbsp; @enabled=1, &nbsp;<br />
&nbsp; &nbsp; @start_step_id=1, &nbsp;<br />
&nbsp; &nbsp; @notify_level_eventlog=0, &nbsp;<br />
&nbsp; &nbsp; @notify_level_email=2, &nbsp;<br />
&nbsp; &nbsp; @notify_level_netsend=2, &nbsp;<br />
&nbsp; &nbsp; @notify_level_page=2, &nbsp;<br />
&nbsp; &nbsp; @delete_level=0, &nbsp;<br />
&nbsp; &nbsp; @description=N'Procédure des statistiques des appels. Cette procédure est lancée toutes les 30 secondes ', &nbsp;<br />
&nbsp; &nbsp; @category_name=N'[Uncategorized (Local)]', &nbsp;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; --&gt; login proprietaire du job <br />
&nbsp; &nbsp; @owner_login_name=N'mylogin', &nbsp;<br />
&nbsp; &nbsp; @notify_email_operator_name=N'', &nbsp;<br />
&nbsp; &nbsp; @notify_netsend_operator_name=N'', &nbsp;<br />
&nbsp; &nbsp; @notify_page_operator_name=N'' <br />
GO <br />
USE [msdb] <br />
GO <br />
DECLARE @schedule_id int <br />
EXEC msdb.dbo.sp_add_jobschedule @job_name=N'JOB_STAT_AGENTS_APPELS', @name=N'Lancement_toutes_les30secondes', &nbsp;<br />
&nbsp; &nbsp; @enabled=1, --&gt; Activé=1 Désactivé = 0 <br />
&nbsp; &nbsp; @freq_type=4, --&gt; Fréquence - périodicité : Quotidienne (@freq_type=4) &nbsp;<br />
&nbsp; &nbsp; @freq_interval=1, --&gt; Schedule par interval regulier &nbsp;<br />
&nbsp; &nbsp; @freq_subday_type=2, --&gt; Fréquence de lancement en seconde (type=2)</div></div>
<p><strong>@freq_subday_interval=30, &#8211;> Frequence de lance du job : toutes les 30 secondes</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; @freq_relative_interval=0, --&gt; Nombre d'occurences mensuelles <br />
&nbsp; &nbsp; @freq_recurrence_factor=1, --&gt; Nombre de semaines ou de mois devant s'écouler entre chaque exécution (freq_recurrence_factor est utilisé uniquement si freq_type a la valeur 8, 16 ou 32) <br />
&nbsp; &nbsp; @active_start_date=20111007, --&gt; Date de debut de demarrage du job &nbsp;<br />
&nbsp; &nbsp; @active_end_date=99991231, --&gt; Date de fin d'activation du job <br />
&nbsp; &nbsp; @active_start_time=0, --&gt; Heure de debut <br />
&nbsp; &nbsp; @active_end_time=235959, --&gt; Heure de fin <br />
&nbsp; &nbsp; @schedule_id = @schedule_id OUTPUT <br />
select @schedule_id <br />
GO</div></div>
<p>En exécutant le script ci-dessus directement dans SSMS je suis arrivé à créer le job avec la fréquence de lancement toutes les 30 secondes.</p>
<p>=> <strong>Après la création du Job il est impossible de modifier la &laquo;&nbsp;Planification&nbsp;&raquo; (schedule) </strong></p>
<p><img src="http://zinzineti.ftp-developpez.com/images/sqlserver2005/modifier_job.jpg" alt="modifier_job" title="modifier_job" /></p>
<p><strong>En cliquant sur le bouton &laquo;&nbsp;Modifier&nbsp;&raquo;, on a le message d&rsquo;erreur suivant</strong></p>
<p><img src="http://zinzineti.ftp-developpez.com/images/sqlserver2005/message_erreur_job.jpg" alt="message_erreur_job" title="message_erreur_job" /></p>
<p>Solution de contournement : Suppression complète du job et création à l&rsquo;aide du script SQL avec avec la modification souhaitée.</p>
<p>=> <strong>La bonne nouvelle c&rsquo;est que sous SQL SERVER 2008 R2, il y a pas de problème</strong></p>
<p><img src="http://zinzineti.ftp-developpez.com/images/sqlserver2005/sqlserver2008.jpg" alt="sqlserver2008" title="sqlserver2008" /></p>
<p>je n&rsquo;ai pas vérifier ce si sous SQL SERVER 2008 on a le même problème ou pas !</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GetSqlBinary</title>
		<link>https://blog.developpez.com/zinzineti/p10311/sql-server-2005/getsqlbinary</link>
		<comments>https://blog.developpez.com/zinzineti/p10311/sql-server-2005/getsqlbinary#comments</comments>
		<pubDate>Thu, 22 Sep 2011 17:12:57 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Depuis que les &#171;&#160;centres d&#8217;appels&#160;&#187; sont devenus des centres de contacts, les télé-conseillers traitent à la fois des appels téléphoniques (voix), des emails, des tchats,&#8230;. Et la plupart des solutions de traitement d&#8217;emails pour centre de contacts stockent les pièces jointes (Attachments) des emails dans des bases de données. Pour SQL Server >= 2005 les pièces jointes sont stockées dans des tables (colonnes) de types varbinary (max) et pour des solutions utilisant le SGBD ORACLE [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Depuis que les &laquo;&nbsp;centres d&rsquo;appels&nbsp;&raquo; sont devenus des centres de contacts, les télé-conseillers traitent à la fois des appels téléphoniques (voix), des emails, des tchats,&#8230;. Et la plupart des solutions de traitement d&rsquo;emails pour centre de contacts stockent les pièces jointes (Attachments) des emails dans des bases de données. Pour SQL Server >= 2005  les pièces jointes sont stockées dans des tables (colonnes) de types varbinary (max) et pour des solutions utilisant le SGBD ORACLE les colonnes utilisées sont souvent de types BLOB ou CLOB ou NCLOB. Les pièces jointes d&rsquo;un email peuvent être des images (.gif,.jpeg,&#8230;), des documents (.doc,.pdf,&#8230;), des vidéos (.wav, .vlc, &#8230;). Ces pièces jointes stockées dans des tables ne sont pas directement lisible par un humain.<br />
Depuis SQL Server il est possible d&rsquo;utiliser des procédures CLR pour décoder les données de type varbinary.<br />
<span id="more-83"></span></p>
<p>Prenons un exemple simple d&rsquo;un model contenant la table des emails (T_Emails) et ces pièces jointes (T_Attachments)</p>
<p><img src="http://zinzineti.ftp-developpez.com/images/CLR_Read_Varbinary/model.jpg" alt="Model_Emails_Attachments" title="Model_Emails_Attachments" /></p>
<p>Nous allons nous intéressé à la table des pièces jointes (T_Attachments) pour montrer comment lire (décoder) le contenu d&rsquo;une colonne varbinary à l&rsquo;aide d&rsquo;une procédure  CLR. Voici le contenu de la table T_Attchments :</p>
<p><img src="http://zinzineti.ftp-developpez.com/images/CLR_Read_Varbinary/attachmentTable.jpg" alt="attachmentTable" title="attachmentTable" /></p>
<p>¤ La première ligne de cette table montre que la pièce jointe est un <strong>fichier .PDF</strong> et le binaire de ce fichier est stocké dans la colonne <strong>AttachmentData</strong> de type <strong>varbinary(max)</strong></p>
<p>¤ La deuxième ligne montre un <strong>fichier .doc</strong> </p>
<p>Comment décoder (rendre lisible) le contenu de la colonne AttachmentData ?</p>
<p>=> <strong>Création dans Visual Studio de la procédure CLR</strong><br />
(image du CLR dans Visual Studio)<br />
<img src="http://zinzineti.ftp-developpez.com/images/CLR_Read_Varbinary/P_CLR.jpg" alt="P_CLR" title="P_CLR" /></p>
<p>(code du CLR)</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">using System; <br />
using System.Data; <br />
using System.Data.SqlClient; <br />
using System.Data.SqlTypes; <br />
using Microsoft.SqlServer.Server; <br />
using System.IO; <br />
&nbsp;<br />
public partial class StoredProcedures <br />
{ <br />
&nbsp; [Microsoft.SqlServer.Server.SqlProcedure] <br />
&nbsp; public static void P_CLR_GetSqlBinary(string DestFolderPath,string fileName) <br />
&nbsp; &nbsp; { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try <br />
&nbsp; &nbsp; &nbsp; &nbsp; { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlConnection cnx = new SqlConnection(@&quot;Data Source=PP-ZINZINDOHOUE\SQL2008R2;User Id=mylogin;Password=myPWD;Initial Catalog=MaBase&quot;); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnx.Open(); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlCommand cmd = new SqlCommand(&quot;P_GenFileFromBinaryData&quot;, cnx); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cmd.CommandType = CommandType.StoredProcedure; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cmd.Parameters.Add(&quot;@FileName&quot;, SqlDbType.VarChar, 2147483647).Value = fileName; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cmd.ExecuteNonQuery(); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = (byte[])cmd.ExecuteScalar(); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileStream fs = new FileStream(DestFolderPath + fileName, FileMode.Create); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.Write(buffer, 0, buffer.Length); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fs.Close(); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cnx.Close(); <br />
&nbsp; &nbsp; &nbsp; &nbsp; } <br />
&nbsp; &nbsp; &nbsp; &nbsp; catch (Exception ex) <br />
&nbsp; &nbsp; &nbsp; &nbsp; { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlContext.Pipe.Send(ex.Message); <br />
&nbsp; &nbsp; &nbsp; &nbsp; } <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; } <br />
};</div></div>
<p>Cette procédure <strong> P_CLR_GetSqlBinary(string DestFolderPath,string fileName)</strong> prend en entrée le répertoire de sortie des données varbinary et le nom du fichier de sortie. Cette procédure CLR appel la procédure T-SQL <strong>P_GenFileFromBinaryData</strong></p>
<p>=> <strong>Création de la procédure stockée P_GenFileFromBinaryData utilisé dans le CLR </strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE PROCEDURE P_GenFileFromBinaryData <br />
@FileName NVARCHAR(1024) <br />
AS &nbsp;<br />
SET NOCOUNT ON <br />
BEGIN <br />
SELECT AttachmentData &nbsp;<br />
FROM MaBase.dbo.T_Attachments &nbsp;<br />
WHERE AttachmentFileName = @FileName <br />
END</div></div>
<p>cette procédure stockée T-SQL sélectionne la colonne AttachmentData  de la table <strong>T_Attachments </strong> dont le nom de la pièce jointe est passé en paramètre (@FileName)</p>
<p>Une fois le code C# généré et déployé dans Visual Studio on peut faire clic droit > Propriétés sur le projet pour enregistrer l&rsquo;Assemblys et configurer la sécurité.</p>
<p>On peut aussi enregistrer l&rsquo;Assemblys et configurer la sécurité depuis SSMS avec le script suivant:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC sp_configure 'clr enabled', 1 <br />
RECONFIGURE WITH OVERRIDE <br />
GO <br />
&nbsp;<br />
ALTER DATABASE MaBase <br />
SET TRUSTWORTHY ON; <br />
GO <br />
&nbsp;<br />
CREATE ASSEMBLY [P_CLR_GetSqlBinary] <br />
AUTHORIZATION [dbo] <br />
FROM '\Projects\GetSqlBinary\GetSqlBinary\bin\Debug\GetSqlBinary.dll' <br />
WITH PERMISSION_SET = SAFE &nbsp;-- UNSAFE ou EXTERNAL_ACCESS <br />
GO</div></div>
<p>=> Test de la procédure CLR<br />
&#8211;> Test 1<br />
<code class="codecolorer text default"><span class="text">EXEC dbo.P_CLR_GetSqlBinary 'E:\TestSQLBinary\','PDFFile.pdf'</span></code></p>
<p>&#8211;> Test 2<br />
<code class="codecolorer text default"><span class="text">EXEC dbo.P_CLR_GetSqlBinary 'E:\TestSQLBinary\','DOCFile.doc'</span></code></p>
<p>=> Résultat des tests</p>
<p><img src="http://zinzineti.ftp-developpez.com/images/CLR_Read_Varbinary/Result.jpg" alt="Resultat" title="Resultat" /></p>
<p><a href="http://research.microsoft.com/apps/pubs/default.aspx?id=64525">Une étude approfondie sur la question : faut-il stocker les gros objets (LOB ) dans une base de données ou sur un système de fichier ?</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utiliser Blat pour envoyer email depuis SQL Server</title>
		<link>https://blog.developpez.com/zinzineti/p9784/sql-server-2005/utiliser_blat_pour_envoyer_email_depuis</link>
		<comments>https://blog.developpez.com/zinzineti/p9784/sql-server-2005/utiliser_blat_pour_envoyer_email_depuis#comments</comments>
		<pubDate>Wed, 02 Mar 2011 21:57:41 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Les éditions Express de SQL Server ne permettent pas l&#8217;envoi d&#8217;email de façon native. Pour contourner cette limitation, on peut utiliser l&#8217;exécutable Blat.exe pour envoyer de façon automatique des emails depuis SQL Server. Voici une procédure stockée qui permet d&#8217;effectuer cette opération. &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- PRE-REQUIS &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8211;&#62;0. T&#233;l&#233;charger l&#39;executable Blat.exe sur le site http://www.blat.net &#8211;&#62;1. Ex&#233;cuter dans la console DOS la commande suivante pour installer BLAT sur la machine SQL SERVER /***************************************************************** blat -install IP_ServeurSMTP votreAdresseEmail [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Les éditions Express de SQL Server ne permettent pas l&rsquo;envoi d&rsquo;email de façon native. Pour contourner cette limitation, on peut utiliser l&rsquo;exécutable Blat.exe pour envoyer de façon automatique des emails depuis SQL Server.<br />
Voici une procédure stockée qui permet d&rsquo;effectuer cette opération.<br />
<span id="more-44"></span></p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- PRE-REQUIS &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt;0. T&eacute;l&eacute;charger l&#39;executable Blat.exe sur le site http://www.blat.net</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt;1. Ex&eacute;cuter dans la console DOS la commande suivante pour installer BLAT sur la machine SQL SERVER</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">/*****************************************************************</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">blat -install IP_ServeurSMTP votreAdresseEmail</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">*******************************************************************/</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt;2. Antivirus : Si un antivirus est pr&eacute;sent sur le serveur, d&eacute;sactiver les r&egrave;gles du genre </font></font><font color="#008000" size="2"><font color="#008000" size="2">&quot;Emp&ecirc;cher les vers diffusion massive d&#39;envoyer des messages &eacute;lectroniques&quot;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&gt;3. Activer l&#39;option avancée xp_cmdshell</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">/*****************************************************************</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">EXEC sp_configure &#39;show advanced options&#39;, 1</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">GO</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">RECONFIGURE</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">GO</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">EXEC sp_configure &#39;xp_cmdshell&#39;, 1</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">GO</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">RECONFIGURE</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">*******************************************************************/</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">/*******************************************************************</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">/* Exemple d&#39;utilisation de la procédure stockée </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">*******************************************************************/</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">EXEC P_Blat_SendEmail</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">@EmplacementFichierBlat = N&#39;E:\testblat\blat.exe&#39;,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">@EmplacementFichierBlatLog = N&#39;E:\testblat\blat.log&#39;,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">@To = N&#39;zinzineti@xxxxx.fr&#39;,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">@Body = N&#39;Envoie email : SQL Serve et Blat&#39;,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">@ServerSMTP = N&#39;IP_ServerSMTP&#39;,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">@Subj = N&#39;Envoi d&#39;&#39;email depuis SQL SERVER l&#39;&#39;aide de Blat&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">*/</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">PROCEDURE</font></font><font size="2"><font color="#000000"> P_Blat_SendEmail</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@EmplacementFichierBlat </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR </font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@EmplacementFichierBlatLog </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR </font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@To </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@Body </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">4000</font><font color="#808080" size="2"><font color="#808080" size="2">)=</font></font><font size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;Envoi d&#39;&#39;email depuis SQL SERVER à l&#39;&#39;aide de Blat&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@ServerSMTP </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">),</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">@Subj </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">)=</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;Envoi d&#39;&#39;email depuis SQL SERVER à l&#39;&#39;aide de Blat&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;@TimeOut INT,</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;@NbTentative INT &#8211;Nombre de tentatives</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NOCOUNT</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; V&eacute;rifier l&#39;existence du fichier blat</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font color="#000000" size="2"> @CMD </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">NVARCHAR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">1500</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DECLARE</font></font><font color="#000000" size="2"> @T_file_exists </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TABLE</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">(</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">file_exists </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">BIT</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> file_is_a_directory </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">BIT</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> parent_directory_exists </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">BIT</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"><font color="#000000"> </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">INSERT</font></font><font size="2"><font color="#000000"> @T_file_exists</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">EXEC</font></font><font color="#000000" size="2"> </font><font color="#800000" size="2"><font color="#800000" size="2">xp_fileexist</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> </font></font><font size="2"><font color="#000000">@EmplacementFichierBlat</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">IF</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">EXISTS</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">(</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font size="2"> file_exists</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font size="2"> @T_file_exists</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHERE</font></font><font size="2"> file_exists </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> 0</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">BEGIN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RAISERROR</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;Le fichier Blat.exe n&#39;&#39;est pas pr&eacute;sent à l&#39;&#39;emplacement &quot;%s&quot; .&#39;</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> 16</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> 1</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> @EmplacementFichierBlat</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">RETURN</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @EmplacementFichierBlat </font><font color="#008000" size="2"><font color="#008000" size="2">&#8211;&#39;E:\testblat\blat.exe&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; -&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; -to &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @To </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; -s &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @ServerSMTP </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; -subject &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @Subj </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; -body &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @Body </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> @CMD </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39; -debug -log &#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> @EmplacementFichierBlatLog </font><font color="#808080" size="2"><font color="#808080" size="2">+</font></font><font color="#000000" size="2"> </font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;&quot;&#39;</font></font><font size="2"><font color="#000000"> </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">EXEC</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">master</font></font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">dbo</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#800000" size="2"><font color="#800000" size="2">xp_cmdshell</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> </font></font><font size="2"><font color="#000000">@CMD</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">END</font></font></span></p>
</blockquote>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Blat v2.5.0 w/GSS encryption (build : Sep 14 2005 22:46:29) <br />
&nbsp;<br />
Win32 console utility to send mail via SMTP or post to usenet via NNTP <br />
by P.Mendes,M.Neal,G.Vollant,T.Charron,T.Musson,H.Pesonen,A.Donchey,C.Hyde <br />
&nbsp; http://www.blat.net <br />
syntax: <br />
&nbsp; Blat &lt;filename&gt; -to &lt;recipient&gt; [optional switches (see below)] <br />
&nbsp; Blat -install &lt;server addr&gt; &lt;sender's addr&gt; [&lt;try&gt;[&lt;port&gt;[&lt;profile&gt;]]] [-q] <br />
&nbsp; Blat -profile [-delete | &quot;&lt;default&gt;&quot;] [profile1] [profileN] [-q] <br />
&nbsp; Blat -h <br />
&nbsp;<br />
-------------------------------- Installation --------------------------------- <br />
-install[SMTP|NNTP|POP3] &lt;server addr&gt; &lt;sender's email addr&gt; [&lt;try n times&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [&lt;port&gt; [&lt;profile&gt; [&lt;username&gt; [&lt;password&gt;]]]]] <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : set server, sender, number of tries and port for profile <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (&lt;try n times&gt; and &lt;port&gt; may be replaced by '-') <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; port defaults are SMTP=25, NNTP=119, POP3=110 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default profile can be specified with a '-' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; username and/or password may be stored to the registry <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order of options is specific <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; use -installNNTP for storing NNTP information <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; use -installPOP3 for storing POP3 information <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (sender and try are ignored, use '-' in place of these) <br />
&nbsp;<br />
--------------------------------- The Basics ---------------------------------- <br />
&lt;filename&gt; &nbsp; &nbsp; &nbsp;: file with the message body to be sent <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if your message body is on the command line, use a hyphen (-) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; as your first argument, and -body followed by your message <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if your message will come from the console/keyboard, use the <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hyphen as your first argument, but do not use -body option. <br />
-of &lt;file&gt; &nbsp; &nbsp; &nbsp;: text file containing more options (also -optionfile) <br />
-to &lt;recipient&gt; : recipient list (also -t) (comma separated) <br />
-tf &lt;file&gt; &nbsp; &nbsp; &nbsp;: recipient list filename <br />
-cc &lt;recipient&gt; : carbon copy recipient list (also -c) (comma separated) <br />
-cf &lt;file&gt; &nbsp; &nbsp; &nbsp;: cc recipient list filename <br />
-bcc &lt;recipient&gt;: blind carbon copy recipient list (also -b) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (comma separated) <br />
-bf &lt;file&gt; &nbsp; &nbsp; &nbsp;: bcc recipient list filename <br />
-maxNames &lt;x&gt; &nbsp; : send to groups of &lt;x&gt; number of recipients <br />
-ur &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : set To: header to Undisclosed Recipients if not using the <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -to and -cc options <br />
-subject &lt;subj&gt; : subject line, surround with quotes to include spaces(also -s) <br />
-ss &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : suppress subject line if not defined <br />
-sf &lt;file&gt; &nbsp; &nbsp; &nbsp;: file containing subject line <br />
-body &lt;text&gt; &nbsp; &nbsp;: message body, surround with quotes to include spaces <br />
-sig &lt;file&gt; &nbsp; &nbsp; : text file containing your email signature <br />
-tag &lt;file&gt; &nbsp; &nbsp; : text file containing taglines, to be randomly chosen <br />
-ps &lt;file&gt; &nbsp; &nbsp; &nbsp;: final message text, possibly for unsubscribe instructions <br />
&nbsp;<br />
----------------------------- Registry overrides ------------------------------ <br />
-p &lt;profile&gt; &nbsp; &nbsp;: send with server, user, and port defined in &lt;profile&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : use username and password if defined in &lt;profile&gt; <br />
-profile &nbsp; &nbsp; &nbsp; &nbsp;: list all profiles in the Registry <br />
-server &lt;addr&gt; &nbsp;: specify SMTP server to be used (optionally, addr:port) <br />
-serverSMTP &lt;addr&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : same as -server <br />
-serverNNTP &lt;addr&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : specify NNTP server to be used (optionally, addr:port) <br />
-serverPOP3 &lt;addr&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : specify POP3 server to be used (optionally, addr:port) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; when POP3 access is required before sending email <br />
-f &lt;sender&gt; &nbsp; &nbsp; : override the default sender address (must be known to server) <br />
-i &lt;addr&gt; &nbsp; &nbsp; &nbsp; : a 'From:' address, not necessarily known to the server <br />
-port &lt;port&gt; &nbsp; &nbsp;: port to be used on the SMTP server, defaults to SMTP (25) <br />
-portSMTP &lt;port&gt;: same as -port <br />
-portNNTP &lt;port&gt;: port to be used on the NNTP server, defaults to NNTP (119) <br />
-portPOP3 &lt;port&gt;: port to be used on the POP3 server, defaults to POP3 (110) <br />
-u &lt;username&gt; &nbsp; : username for AUTH LOGIN (use with -pw) <br />
-pw &lt;password&gt; &nbsp;: password for AUTH LOGIN (use with -u) <br />
-pu &lt;username&gt; &nbsp;: username for POP3 LOGIN (use with -ppw) <br />
-ppw &lt;password&gt; : password for POP3 LOGIN (use with -pu) <br />
&nbsp;<br />
---------------------- Miscellaneous RFC header switches ---------------------- <br />
-organization &lt;organization&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Organization field (also -o and -org) <br />
-ua &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : include User-Agent header line instead of X-Mailer <br />
-x &lt;X-Header: detail&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : custom 'X-' header. &nbsp;eg: -x &quot;X-INFO: Blat is Great!&quot; <br />
-noh &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: prevent X-Mailer/User-Agent header from showing Blat homepage <br />
-noh2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : prevent X-Mailer header entirely <br />
-d &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: request disposition notification <br />
-r &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: request return receipt <br />
-charset &lt;cs&gt; &nbsp; : user defined charset. &nbsp;The default is ISO-8859-1 <br />
-a1 &lt;header&gt; &nbsp; &nbsp;: add custom header line at the end of the regular headers <br />
-a2 &lt;header&gt; &nbsp; &nbsp;: same as -a1, for a second custom header line <br />
-dsn &lt;nsfd&gt; &nbsp; &nbsp; : use Delivery Status Notifications (RFC 3461) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n = never, s = successful, f = failure, d = delayed <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; can be used together, however N takes precedence <br />
-hdrencb &nbsp; &nbsp; &nbsp; &nbsp;: use base64 for encoding headers, if necessary <br />
-hdrencq &nbsp; &nbsp; &nbsp; &nbsp;: use quoted-printable for encoding headers, if necessary <br />
-priority &lt;pr&gt; &nbsp;: set message priority 0 for low, 1 for high <br />
&nbsp;<br />
----------------------- Attachment and encoding options ----------------------- <br />
-attach &lt;file&gt; &nbsp;: attach binary file(s) to message (filenames comma separated) <br />
-attacht &lt;file&gt; : attach text file(s) to message (filenames comma separated) <br />
-attachi &lt;file&gt; : attach text file(s) as INLINE (filenames comma separated) <br />
-embed &lt;file&gt; &nbsp; : embed file(s) in HTML. &nbsp;Object tag in HTML must specify <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content-id using cid: tag. &nbsp;eg: &lt;img src=&quot;cid:image.jpg&quot;&gt; <br />
-af &lt;file&gt; &nbsp; &nbsp; &nbsp;: file containing list of binary file(s) to attach (comma <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; separated) <br />
-atf &lt;file&gt; &nbsp; &nbsp; : file containing list of text file(s) to attach (comma <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; separated) <br />
-aef &lt;file&gt; &nbsp; &nbsp; : file containing list of embed file(s) to attach (comma <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; separated) <br />
-base64 &nbsp; &nbsp; &nbsp; &nbsp; : send binary files using base64 (binary MIME) <br />
-uuencode &nbsp; &nbsp; &nbsp; : send binary files UUEncoded <br />
-enriched &nbsp; &nbsp; &nbsp; : send an enriched text message (Content-Type=text/enriched) <br />
-unicode &nbsp; &nbsp; &nbsp; &nbsp;: message body is in 16- or 32-bit Unicode format <br />
-html &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : send an HTML message (Content-Type=text/html) <br />
-alttext &lt;text&gt; : plain text for use as alternate text <br />
-alttextf &lt;file&gt;: plain text file for use as alternate text <br />
-mime &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : MIME Quoted-Printable Content-Transfer-Encoding <br />
-8bitmime &nbsp; &nbsp; &nbsp; : ask for 8bit data support when sending MIME <br />
-multipart &lt;size&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : send multipart messages, breaking attachments on &lt;size&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KB boundaries, where &lt;size&gt; is per 1000 bytes <br />
-nomps &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: do not allow multipart messages <br />
&nbsp;<br />
---------------------------- NNTP specific options ---------------------------- <br />
-groups &lt;usenet groups&gt; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : list of newsgroups (comma separated) <br />
&nbsp;<br />
-------------------------------- Other options -------------------------------- <br />
-h &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: displays this help (also -?, /?, -help or /help) <br />
-q &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: suppresses all output to the screen <br />
-debug &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: echoes server communications to a log file or screen <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (overrides -q if echoes to the screen) <br />
-log &lt;file&gt; &nbsp; &nbsp; : log everything but usage to &lt;file&gt; <br />
-timestamp &nbsp; &nbsp; &nbsp;: when -log is used, a timestamp is added to each log line <br />
-ti &lt;n&gt; &nbsp; &nbsp; &nbsp; &nbsp; : set timeout to 'n' seconds. &nbsp;Blat will wait 'n' seconds for <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; server responses <br />
-try &lt;n times&gt; &nbsp;: how many times blat should try to send (1 to 'INFINITE') <br />
-binary &nbsp; &nbsp; &nbsp; &nbsp; : do not convert ASCII | (pipe, 0x7c) to CrLf in the message <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body <br />
-hostname &lt;hst&gt; : select the hostname used to send the message via SMTP <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this is typically your local machine name <br />
-raw &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: do not add CR/LF after headers <br />
-delay &lt;x&gt; &nbsp; &nbsp; &nbsp;: wait x seconds between messages being sent when used with <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -maxnames or -multipart <br />
-comment &lt;char&gt; : use this character to mark the start of commments in <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options files and recipient list files. &nbsp;The default is ; <br />
-superdebug &nbsp; &nbsp; : hex/ascii dump the data between Blat and the server <br />
-superdebugT &nbsp; &nbsp;: ascii dump the data between Blat and the server <br />
------------------------------------------------------------------------------- <br />
&nbsp;<br />
Note that if the '-i' option is used, &lt;sender&gt; is included in 'Reply-to:' <br />
and 'Sender:' fields in the header of the message. <br />
&nbsp;<br />
Optionally, the following options can be used instead of the -f and -i <br />
options: <br />
&nbsp;<br />
-mailfrom &lt;addr&gt; &nbsp; The RFC 821 MAIL From: statement <br />
-from &lt;addr&gt; &nbsp; &nbsp; &nbsp; The RFC 822 From: statement <br />
-replyto &lt;addr&gt; &nbsp; &nbsp;The RFC 822 Reply-To: statement <br />
-returnpath &lt;addr&gt; The RFC 822 Return-Path: statement <br />
-sender &lt;addr&gt; &nbsp; &nbsp; The RFC 822 Sender: statement <br />
&nbsp;<br />
For backward consistency, the -f and -i options have precedence over these <br />
RFC 822 defined options. &nbsp;If both -f and -i options are omitted then the <br />
RFC 821 MAIL FROM statement will be defaulted to use the installation-defined <br />
default sender address.</div></div>
<p><a href="http://www.blat.net/syntax/syntax.html">Pour plus de détails sur les autres options de Blat</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
&#8212; Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mettre à jour une table à partir des données d&#8217;une autre table</title>
		<link>https://blog.developpez.com/zinzineti/p9698/sql-server-2005/mettre_a_jour_une_table_a_partir_des_don</link>
		<comments>https://blog.developpez.com/zinzineti/p9698/sql-server-2005/mettre_a_jour_une_table_a_partir_des_don#comments</comments>
		<pubDate>Fri, 21 Jan 2011 17:25:10 +0000</pubDate>
		<dc:creator><![CDATA[zinzineti]]></dc:creator>
				<category><![CDATA[SQL SERVER 2005]]></category>
		<category><![CDATA[SQL SERVER 2008]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Juste un petit topo pour mettre à jour (MAJ) une table à partir des données d&#8217;une autre table. /!\Attention : les tables concernées doivent avoir la même collation /* ================================================================================== &#8211; Description : Mettre jour une table partir des donn&#233;es d&#39;une autre table &#8211; Auteur : Etienne ZINZINDOHOUE &#8211; SQL SERVER 2005/2008R2 ==================================================================================*/ CREATE TABLE T1(id int, c1 char(1)) GO CREATE TABLE T2(id int, c1 char(1)) GO &#8211;jeu de donn&#233;es INSERT INTO T1 SELECT 1,&#39;a&#39; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Juste un petit topo pour mettre à jour (MAJ) une table à partir des données d&rsquo;une autre table.<br />
<strong>/!\Attention : les tables concernées doivent avoir la même collation</strong><br />
<span id="more-41"></span></p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">/* ==================================================================================</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Description : Mettre jour une table partir des donn&eacute;es d&#39;une autre table</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Auteur : Etienne ZINZINDOHOUE</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; SQL SERVER 2005/2008R2 </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">==================================================================================*/</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TABLE</font></font><font color="#000000" size="2"> T1</font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">id </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> c1 </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">char</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">1</font><font color="#808080" size="2"><font color="#808080" size="2">))</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TABLE</font></font><font color="#000000" size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">id </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2"> c1 </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">char</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">1</font><font color="#808080" size="2"><font color="#808080" size="2">))</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;jeu de donn&eacute;es</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">INSERT</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">INTO</font></font><font size="2"><font color="#000000"> T1 </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> 1</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;a&#39;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UNION</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> 2</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;b&#39;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UNION</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> 3</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;c&#39;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">INSERT</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">INTO</font></font><font size="2"><font color="#000000"> T2 </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> 1</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;1&#39;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UNION</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> 2</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#ff0000" size="2"><font color="#ff0000" size="2">&#39;2&#39;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Mettre &agrave; jour T1(c1) en fonction de T2(c1)</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; R&eacute;sultat attendu apr&egrave;s la MAJ</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font size="2">T1 </font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;&#8212;&#8212;&#8212;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font size="2">id    c1</font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;   &#8212;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font size="2">1     1</font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font size="2">2     2</font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font size="2">3     c</font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;La requ&ecirc;te de MAJ</font></font></font></font></span></p>
<p><strong>&#8211;>> Update simple</strong></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UPDATE</font></font><font size="2"><font color="#000000"> T1 </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">c1</font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">c1</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font color="#000000" size="2"> T2 </font><font color="#808080" size="2"><font color="#808080" size="2">INNER</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">JOIN</font></font><font color="#000000" size="2"> T1 </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font><font color="#000000" size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">id </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">id</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;V&eacute;rification de la MAJ</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">*</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font size="2"><font color="#000000"> T1</font></font></font></font></span></p>
<p>
<strong>&#8211;>>Autre Méthode, utilisation du CTE (Common Table Expressions ), introduit depuis SQL 2005	</strong><br />
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</font></font></font></font></span></p>
<p><span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; M&eacute;thode avec un CTE </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WITH</font></font><font color="#000000" size="2"> cte </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS </font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> id</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">c1 </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font color="#000000" size="2"> T1</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UPDATE</font></font><font size="2"><font color="#000000"> cte </font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font color="#000000" size="2"> cte</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">c1 </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">c1</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font color="#000000" size="2"> cte </font><font color="#808080" size="2"><font color="#808080" size="2">INNER</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">JOIN</font></font><font color="#000000" size="2"> T2 </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font><font color="#000000" size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">id </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> cte</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">id</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;V&eacute;fication de la MAJ</font></font></font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">*</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font size="2"><font color="#000000"> T1</font></font></font></font></span></p>
<p><strong>&#8211;>> Le top du top c&rsquo;est l&rsquo;utilisation de MERGE introduit depuis SQL SERVER 2008. Comment ça marche ?</strong></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Utilisation de MERGE</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">MERGE</font></font><font color="#000000" size="2"> T1 </font><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Table cible (TARGET)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">USING</font></font><font size="2"> T2 </font><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Table source (SOURCE)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font><font size="2"> T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">id </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">id</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHEN</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">MATCHED</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">THEN</font></font><font size="2"> </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UPDATE</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">c1 </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">c1</font><font color="#808080" size="2"><font color="#808080" size="2">;</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;V&eacute;rification</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">*</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">from</font></font><font size="2"><font color="#000000"> T1</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Update + Insert (Insert si la ligne existe dans T2 mais pas dans T1)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">GO</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">MERGE</font></font><font color="#000000" size="2"> T1 </font><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Table cible (TARGET)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">USING</font></font><font size="2"> T2 </font><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Table source (SOURCE)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">ON</font></font><font size="2"> T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">id </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">id</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHEN</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">MATCHED</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">THEN</font></font><font size="2"> </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UPDATE</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font size="2"> T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">c1 </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">c1</font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHEN</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">NOT</font></font><font size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">MATCHED</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">BY</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TARGET</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">THEN</font></font><font size="2"> </font><font color="#008000" size="2"><font color="#008000" size="2">&#8211; si l&#39;id existe dans T2 mais pas dans T1 alors ins&eacute;rer cette nouvelle ligne dans T1 </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">INSERT </font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">id</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2">T1</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">c1</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font><font size="2"> </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">VALUES </font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font size="2">T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">id</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2">T2</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">c1</font><font color="#808080" size="2"><font color="#808080" size="2">);</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Avec les options MATCHED et NOT MATCHED on peut r&eacute;aliser plusieurs op&eacute;rations en une seule fois : Update/Insert/Delete<span style="display: none"> </span></font></font></span></p>
</blockquote>
<p><strong>&#8211;> Simuler la commande MERGE sous SQL SERVER 2005</strong></p>
<blockquote>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211; Table temporaire pour stocker l&#39;ID des nouveaux contacts </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">CREATE</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TABLE</font></font><font color="#000000" size="2"> #updated_GUID</font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> </font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">objectGUID </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">nvarchar</font></font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font><font color="#000000" size="2">100</font><font color="#808080" size="2"><font color="#808080" size="2">))</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Mis &agrave; jour des contacts à partir de la table cible TMP_Contacts</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">UPDATE</font></font><font size="2"><font color="#000000"> Contacts</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SET</font></font><font size="2"><font color="#000000"> </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">FirstName </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">FirstName </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">Initials </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">Initials</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">LastName </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">LastName </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">Company </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">Company</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">BusinessPhone </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">BusinessPhone </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">EmailAddress </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">EmailAddress</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Recupérer l&rsquo;ID des contacts mis à jours</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">OUTPUT</font></font><font color="#000000" size="2"> inserted</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">objectGUID </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">INTO</font></font><font size="2"><font color="#000000"> #updated_GUID</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font color="#000000" size="2"> Contacts c</font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000"> TMP_Contact t</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHERE</font></font><font color="#000000" size="2"> c</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">objectGUID </font><font color="#808080" size="2"><font color="#808080" size="2">=</font></font><font color="#000000" size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2"><font color="#000000">objectGUID</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Insertion des nouveaux contacts</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">INSERT</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">INTO</font></font><font color="#000000" size="2"> Contacts</font><font color="#808080" size="2"><font color="#808080" size="2">(</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">FirstName </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">Initials</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">LastName</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">Company </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">BusinessPhone </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font color="#000000" size="2">EmailAddress</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font size="2"><font color="#000000"> </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font size="2">FirstName </font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">Initials</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">LastName</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">Company </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">BusinessPhone </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"><font color="#000000">EmailAddress</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font size="2"><font color="#000000"> TMP_Contacts t </font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">WHERE</font></font><font color="#000000" size="2"> t</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font color="#000000" size="2">objectGUID </font><font color="#808080" size="2"><font color="#808080" size="2">NOT</font></font><font color="#000000" size="2"> </font><font color="#808080" size="2"><font color="#808080" size="2">IN(</font></font><font color="#0000ff" size="2"><font color="#0000ff" size="2">SELECT</font></font><font color="#000000" size="2"> objectGUID </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">FROM</font></font><font color="#000000" size="2"> #updated_GUID</font><font color="#808080" size="2"><font color="#808080" size="2">)</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#008000" size="2"><font color="#008000" size="2">&#8211;Supprimer la table temporaire</font></font></span></p>
<p>
	<span style="font-family: courier new, courier, monospace"><font color="#0000ff" size="2"><font color="#0000ff" size="2">DROP</font></font><font color="#000000" size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">TABLE</font></font><font size="2"><font color="#000000"> #updated_GUID</font></font></span></p>
</blockquote>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
Etienne ZINZINDOHOUE<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
