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

<channel>
	<title>Le blog de SQLpro &#187; SQL Server 2000</title>
	<atom:link href="https://blog.developpez.com/sqlpro/pcategory/ms-sql-server/sql-server-2000/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/sqlpro</link>
	<description>Le SQL pour SQL Server, PostGreSQL et tous les autres SGBDR</description>
	<lastBuildDate>Thu, 15 Oct 2020 12:59:17 +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>Agrégation des statistiques d&#8217;IO d&#8217;une requête</title>
		<link>https://blog.developpez.com/sqlpro/p13157/ms-sql-server/agregation-des-statistiques-dio-dune-requete</link>
		<comments>https://blog.developpez.com/sqlpro/p13157/ms-sql-server/agregation-des-statistiques-dio-dune-requete#comments</comments>
		<pubDate>Thu, 28 Dec 2017 18:55:58 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[ES]]></category>
		<category><![CDATA[IO]]></category>
		<category><![CDATA[performance requête]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[STATISTICS IO]]></category>
		<category><![CDATA[statistiques entrées sorties]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=778</guid>
		<description><![CDATA[Si le paramétrage SET STATISTICS IO ON de Microsoft SQL Server permet de savoir, table par table les statistiques d&#8217;entrées/sorties (IO pour Input/Output) des requêtes, il n&#8217;est pas toujours facile de s&#8217;y repérer lorsque la requête est complexe et fait appel à de multiples tables. Voici une procédure qui en effectue la synthèse. Rappelons que [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Si le paramétrage <strong>SET STATISTICS IO ON</strong> de Microsoft SQL Server permet de savoir, table par table les statistiques d&rsquo;entrées/sorties (IO pour Input/Output) des requêtes, il n&rsquo;est pas toujours facile de s&rsquo;y repérer lorsque la requête est complexe et fait appel à de multiples tables. Voici une procédure qui en effectue la synthèse.<br />
<span id="more-778"></span><br />
Rappelons que les statistiques IO sont le nombre de pages lues par le moteur SQL pour exécuter une requête. Le paramètre de session STATISTICS IO peut être mis à ON ou OFF. Par défaut il est à OFF. Mis sur ON, il permet, dans SQL Server Management Studio (SSMS), de voir le nombre de pages accédées pour une requête ou un lot de requête. C&rsquo;est une série de message d&rsquo;une ligne commençant par &laquo;&nbsp;Table&#8230;&nbsp;&raquo; qui suit immédiatement le message indiquant le nombre de lignes affectées par la requête.<br />
<div id="attachment_780" style="width: 530px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO.jpg" alt="SQL Server onglet message STATISTICS IO" width="520" height="310" class="size-full wp-image-780" /></a><p class="wp-caption-text">SQL Server onglet message STATISTICS IO</p></div> </p>
<p>Néanmoins il est assez difficile de lire tout cela et d&rsquo;en déduire une tendance globale.<br />
Ne serait-ce pas plus intéressante de les présenter de cette manière :<br />
<div id="attachment_781" style="width: 989px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL.jpg" alt="SQL Server STATISTICS IO aggregate" width="979" height="329" class="size-full wp-image-781" /></a><p class="wp-caption-text">Statistiques IO SQL Server avec totaux et agrégation</p></div></p>
<p>La petite procédure que voici permet justement d&rsquo;effectuer cette tâche. Il suffit de lui passer le texte complet des message d&rsquo;IO et elle vous retournera tout cela, formaté, totalisé et agrégé !</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">USE</span> msdb;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">CREATE</span> SCHEMA S_DBA;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> S_DBA<span style="color: #66cc66;">.</span>P_SPLIT_STATS_IO @<span style="color: #993333; font-weight: bold;">DATA</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @LINE NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">SQL</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @L <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>LINE NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">800</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @T <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sysname<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SCAN_COUNT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOGICAL_READS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PHYSICAL_READS &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; READ_AHEAD_READS &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_LOGICAL_READS &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_PHYSICAL_READS &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOB_READ_AHEAD_READS &nbsp; <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
WHILE CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">,</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> &nbsp;<span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @L <span style="color: #993333; font-weight: bold;">SELECT</span> @LINE;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">DATA</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">RIGHT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">,</span> LEN<span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> CHARINDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">DATA</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @L <span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">DATA</span>;<br />
<span style="color: #993333; font-weight: bold;">DELETE</span> @L <span style="color: #993333; font-weight: bold;">WHERE</span> LINE <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span> <span style="color: #993333; font-weight: bold;">OR</span> LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> N<span style="color: #ff0000;">'%Table %'</span> <span style="color: #993333; font-weight: bold;">COLLATE</span> French_BIN;<br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @L <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Nombre d'</span><span style="color: #ff0000;">'analyses%'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">--&gt; français</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Table '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures logiques '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures physiques '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' lectures anticipées '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'de données d'</span><span style="color: #ff0000;">'objets volumineux '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @L <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;LINE <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Scan count%'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #808080; font-style: italic;">--&gt; anglais</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Table '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'. Scan count '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">','</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' logical reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' physical reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">' read-ahead reads '</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'lob'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">UPDATE</span> @L <span style="color: #993333; font-weight: bold;">SET</span> LINE <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>LINE<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'SELECT '</span> <span style="color: #66cc66;">+</span> LINE <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' UNION ALL '</span> <span style="color: #993333; font-weight: bold;">FROM</span> @L;<br />
<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">,</span> LEN<span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @T<br />
<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">WITH</span> <br />
T <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T<br />
<span style="color: #993333; font-weight: bold;">UNION</span> <span style="color: #993333; font-weight: bold;">ALL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'°°° TOTAL °°°'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>SCAN_COUNT<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOGICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PHYSICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_LOGICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_PHYSICAL_READS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOB_READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T<br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <br />
<span style="color: #993333; font-weight: bold;">FROM</span> T<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #993333; font-weight: bold;">CASE</span> <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'°°° TOTAL °°°'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">END</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOGICAL_READS <span style="color: #993333; font-weight: bold;">DESC</span>; &nbsp;<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>SCAN_COUNT<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_SCANS<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>LOGICAL_READS <span style="color: #66cc66;">+</span> LOB_LOGICAL_READS<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_LOGICAL_READS<span style="color: #66cc66;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SUM</span><span style="color: #66cc66;">&#40;</span>PHYSICAL_READS <span style="color: #66cc66;">+</span> READ_AHEAD_READS <span style="color: #66cc66;">+</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LOB_PHYSICAL_READS <span style="color: #66cc66;">+</span> LOB_READ_AHEAD_READS<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_PHYSICAL_READS<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; @T;<br />
<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p><strong>Exemple d&rsquo;utilisation :</strong></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">EXECUTE</span> msdb<span style="color: #66cc66;">.</span>S_DBA<span style="color: #66cc66;">.</span>P_SPLIT_STATS_IO <span style="color: #ff0000;">'Table '</span><span style="color: #ff0000;">'PARAM_EAC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 13, lectures logiques 26, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'Worktable'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 0, lectures logiques 0, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'VAL_PARAM_EAC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 1, lectures logiques 59, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'ESP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 31, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'TL_EXP_COOP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 178, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'UC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 5633, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'TL_PP_UC'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 1254, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PG'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 85289, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'Worktable'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 0, lectures logiques 0, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PG'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 1, lectures logiques 437, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'PP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 7271, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'EXP'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 1996, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.<br />
Table '</span><span style="color: #ff0000;">'VAR'</span><span style="color: #ff0000;">'. Nombre d'</span><span style="color: #ff0000;">'analyses 49, lectures logiques 866, lectures physiques 0, lectures anticipées 0, lectures logiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures physiques de données d'</span><span style="color: #ff0000;">'objets volumineux 0, lectures anticipées de données d'</span><span style="color: #ff0000;">'objets volumineux 0.'</span></div></div>
<p>Le résultat :<br />
<div id="attachment_782" style="width: 986px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL-results.jpg"><img src="http://blog.developpez.com/sqlpro/files/2017/12/STATISTICS_IO_GLOBAL-results.jpg" alt="Les statistiques d&#039;IO d&#039;une requête, sus forme tabulaire, totalisés et agrégés" width="976" height="337" class="size-full wp-image-782" /></a><p class="wp-caption-text">Les statistiques d&rsquo;IO d&rsquo;une requête, sous forme tabulaire, totalisés et agrégés</p></div></p>
<p><strong>QUELQUES EXPLICATIONS SUR LES MÉTRIQUES</strong></p>
<li><strong>analyses</strong> (scan count) : nombre de fois ou l&rsquo;exécuteur de requête a du pénétrer dans un index de la table ou dans la table (en cas de parallélisme, autant de fois que de threads&#8230;)</li>
<li><strong>lectures logiques</strong> (logical reads) : nombre de pages lues en RAM</li>
<li><strong>lectures physiques</strong> (physical reads) : nombre de pages lues depuis le disque (avec transfert en RAM) en mode aléatoire.</li>
<li><strong>lectures anticipées</strong> (read-ahead physical read) : nombre de pages lues depuis le disque (avec transfert en RAM) en mode continu.</li>
<li>&#8230;<strong>d&rsquo;objets volumineux</strong> (lob &#8230;) : nombre de pages &#8230; pour les &laquo;&nbsp;Large OBjects&nbsp;&raquo;.
</li>
<p><strong>NOTA </strong>: cet outil fonctionne que votre serveur soit en anglais ou français.</p>
<p><strong>LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE * LE CODE</strong><br />
<a href="http://sqlpro.developpez.com/_fichierSQL/SET_STATISTIS_IO_AGGREGATE.txt" title="Fichier du code" target="_blank">Le code !</a></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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Une fonction de comptage d&#8217;occurrence</title>
		<link>https://blog.developpez.com/sqlpro/p13156/ms-sql-server/une-fonction-de-comptage-doccurrence</link>
		<comments>https://blog.developpez.com/sqlpro/p13156/ms-sql-server/une-fonction-de-comptage-doccurrence#comments</comments>
		<pubDate>Thu, 16 Nov 2017 17:51:42 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[caractères]]></category>
		<category><![CDATA[comptage]]></category>
		<category><![CDATA[fonction]]></category>
		<category><![CDATA[occurrence]]></category>
		<category><![CDATA[SQL server]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=776</guid>
		<description><![CDATA[La petite fonction qui suit permet de compter le nombre de fois ou un caractère est présent dans une chaine de caractères. CREATE FUNCTION F_COUNT_CHAR&#40;@STR NVARCHAR&#40;MAX&#41;, @CHR NCHAR&#40;1&#41;&#41; RETURNS INT WITH RETURNS NULL ON NULL INPUT AS BEGIN DECLARE @NBR INT, @POS INT; SELECT @NBR = 0, @POS = CHARINDEX&#40;@CHR, @STR&#41;; WHILE @POS &#62; 0 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>La petite fonction qui suit permet de compter le nombre de fois ou un caractère est présent dans une chaine de caractères.</p>
<p><span id="more-776"></span></p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span>@STR NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @CHR <span style="color: #993333; font-weight: bold;">NCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">INT</span><br />
<span style="color: #993333; font-weight: bold;">WITH</span> <span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">INPUT</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @NBR <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">,</span> @POS <span style="color: #993333; font-weight: bold;">INT</span>;<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @NBR <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> @POS <span style="color: #66cc66;">=</span> CHARINDEX<span style="color: #66cc66;">&#40;</span>@CHR<span style="color: #66cc66;">,</span> @STR<span style="color: #66cc66;">&#41;</span>;<br />
WHILE @POS <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @NBR <span style="color: #66cc66;">=</span> @NBR <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @POS <span style="color: #66cc66;">=</span> CHARINDEX<span style="color: #66cc66;">&#40;</span>@CHR<span style="color: #66cc66;">,</span> @STR<span style="color: #66cc66;">,</span> @POS <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">RETURN</span> @NBR;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p>Exemples d&rsquo;utilisation :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- exemple &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- résultat</span><br />
<span style="color: #808080; font-style: italic;">------------------------------------------- ------------</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'abracadabra'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">--&gt; 5</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; 0</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; 0</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">--&gt; 0</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; NULL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'a'</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;">--&gt; NULL</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> dbo<span style="color: #66cc66;">.</span>F_COUNT_CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">--&gt; NULL</span></div></div>
<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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Qui est leader dans les bases de données en 2016 ?</title>
		<link>https://blog.developpez.com/sqlpro/p13115/ms-sql-server/qui-est-leader-dans-les-bases-de-donnees-en-2016</link>
		<comments>https://blog.developpez.com/sqlpro/p13115/ms-sql-server/qui-est-leader-dans-les-bases-de-donnees-en-2016#comments</comments>
		<pubDate>Thu, 27 Oct 2016 14:43:33 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[bases de données]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[étude]]></category>
		<category><![CDATA[Gartner]]></category>
		<category><![CDATA[leader]]></category>
		<category><![CDATA[SGBD]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=675</guid>
		<description><![CDATA[Selon l&#8217;étude 2016 du groupe Gartner au sujet des bases de données opérationnelles d&#8217;entreprise (OPDBMS), Microsoft est le n°1 sur les deux axes de mesure : facilité d&#8217;utilisation et visionnaire. Microsoft détient l&#8217;un des systèmes de bases de données relationnelles les mieux conçu, les plus utilisés et le plus fiable avec SQL Server, incorporant un [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Selon l&rsquo;<a href="https://www.gartner.com/doc/reprints?id=1-3JD7HF0&amp;ct=161005&amp;st=sb" title="Magic Quadrant for Operational Database Management Systems 2016" target="_blank">étude 2016 du groupe Gartner au sujet des bases de données opérationnelles d&rsquo;entreprise (OPDBMS)</a>, Microsoft est le n°1 sur les deux axes de mesure : facilité d&rsquo;utilisation et visionnaire.</p>
<div id="attachment_677" style="width: 635px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2016/10/Gartner-Magic-Quadrant_SGBD_2016.png"><img src="http://blog.developpez.com/sqlpro/files/2016/10/Gartner-Magic-Quadrant_SGBD_2016-1024x1024.png" alt="Source : Gartner - Magic Quadrant for Operational Database Management Systems 2016" width="625" height="625" class="size-large wp-image-677" /></a><p class="wp-caption-text">Source : Gartner &#8211; Magic Quadrant for Operational Database Management Systems 2016</p></div>
<p>Microsoft détient l&rsquo;un des systèmes de bases de données relationnelles les mieux conçu, les plus utilisés et le plus fiable avec <a href="https://www.microsoft.com/fr-fr/server-cloud/products/sql-server/" target="_blank">SQL Server</a>, incorporant un moteur <a href="https://msdn.microsoft.com/fr-fr/library/dn133186.aspx" title="SQL Server 2016 in memory" target="_blank">&laquo;&nbsp;in memory&nbsp;&raquo;</a> (IMDBMS).<br />
Mais il se trouve que Microsoft est aussi le numéro deux du cloud derrière Amazon (<a href="https://azure.microsoft.com/fr-fr/services/sql-database/" title="Azure Database, la solution &quot;cloud&quot; de SQL Server" target="_blank">Azure SQL Database</a>).<br />
Il offre aussi différentes technologies complémentaire de type NoSQL avec <a href="https://azure.microsoft.com/fr-fr/services/documentdb/" title="NoSQL avec Azure DocumentDB" target="_blank">Azure DocumentDB</a> (un SGBD de type &laquo;&nbsp;document&nbsp;&raquo;) et <a href="https://azure.microsoft.com/fr-fr/documentation/articles/storage-table-design-guide/" title="Base de données NoSQL sous forme de paires clé/valeur avec Azure Table" target="_blank">Azure Tables</a> (un SGBDR de type paire clef/valeur).<br />
Très présent dans le cloud, y compris de manière hybride (une base SQL Serveur locale peut avoir une partie de ses données dans le cloud via le concept de &laquo;&nbsp;<a href="https://msdn.microsoft.com/fr-fr/library/dn935011.aspx" title="SQL Server : concept de &quot;stretch tables&quot;" target="_blank">stretch tables</a>&laquo;&nbsp;), Microsoft offre aussi de nombreuses possibilité analytiques ou mobile.</p>
<p>Pour la troisième année consécutive Mictrosoft est numéro 2 en part de marché sur le plan financier, derrière Oracle dont le Gartner Group a remonté comme point négatif de l&rsquo;étude, les problèmes de coûts, de complexité de licences et noté un rapport qualité prix jugé négatif par les clients.</p>
<p>Mais ce qui fait la force de Microsoft depuis toujours, et celle en particulier de ses solutions de bases de données, c&rsquo;est la facilité d&rsquo;utilisation (l&rsquo;un des meilleurs scores de l&rsquo;étude) et de migration de version (80% des clients ont trouvés que la migration des bases était plus facile que prévue ou autant que prévu)&#8230;</p>
<p>Les seuls problèmes pointés du doigt de manière négatives par le Gartner Group sont exclusivement celles liées au marketing, canaux de vente et distribution des solutions Microsoft ou l&rsquo;éditeur reste encore perçut par certains comme un acteurs pour de petites solutions&#8230;<br />
Finalement aucune critique technique ni financière ne vient ternir l&rsquo;image d&rsquo;excellence de Microsoft dans le domaines des bases de données d&rsquo;entreprise ce qui tend à prouver que ce classement de leader est largement mérité !</p>
<p>***</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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Un DATEDIFF amélioré</title>
		<link>https://blog.developpez.com/sqlpro/p12900/ms-sql-server/un-datediff-ameliore</link>
		<comments>https://blog.developpez.com/sqlpro/p12900/ms-sql-server/un-datediff-ameliore#comments</comments>
		<pubDate>Thu, 13 Aug 2015 14:19:50 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[BIGINT]]></category>
		<category><![CDATA[calcul]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[DATEDIFF]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[différence]]></category>
		<category><![CDATA[SQL server]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[Transact SQL]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=584</guid>
		<description><![CDATA[La fonction DATEDIFF retourne un entier de type INT. Cependant cela ne suffit pas dans certaines cas : granularité de calcul trop fine (milliseconde par exemple) ou plages de valeurs trop étendues. La fonction F_DATEDIFF_BIG répond a cette problématique en vous offrant une valeur de sortie sous forme de BIGINT. Voici cette fonction. Toutes les [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>La fonction DATEDIFF retourne un entier de type INT. Cependant cela ne suffit pas dans certaines cas : granularité de calcul trop fine (milliseconde par exemple) ou plages de valeurs trop étendues. La fonction F_DATEDIFF_BIG répond a cette problématique en vous offrant une valeur de sortie sous forme de BIGINT.<br />
<span id="more-584"></span></p>
<p>Voici cette fonction. Toutes les explications et la manière de s&rsquo;en servir sont dans la cartouche.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> dbo<span style="color: #66cc66;">.</span>F_DATEDIFF_BIG <span style="color: #66cc66;">&#40;</span>@DATEPART <span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @DT1 DATETIME2<span style="color: #66cc66;">,</span> @DT2 DATETIME2<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #808080; font-style: italic;">/******************************************************************************<br />
* FONCTION UDF SCALAIRE dbo.F_DATEDIFF_BIG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2015-08-13 *<br />
*******************************************************************************<br />
* Frédéric BROUARD &nbsp;- &nbsp;alias SQLpro &nbsp; - &nbsp; SARL SQL SPOT &nbsp;- &nbsp;SQLpro@outlook.fr *<br />
* Architecte de données : &nbsp;expertise, audit, conseil, formation, modélisation *<br />
* tuning, sur les SGBD Relationnels, le langage SQL, MS SQL Server/PostGreSQL *<br />
* blog: http://blog.developpez.com/sqlpro &nbsp;site: http://sqlpro.developpez.com *<br />
*******************************************************************************<br />
* Cette fonction étend la capacité de la fonction intégrée DATEDIFF lorsqu'il *<br />
* y a dépassement de capacité pour la valeur résultante. Exemple : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* SELECT DATEDIFF(minute, '0001-01-01', '9999-12-31'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* --&gt; Msg 535, Niveau 16, État 0, Ligne 91 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp; La fonction datediff a provoqué un dépassement de capacité. Le nombre &nbsp; *<br />
* &nbsp; &nbsp; de parties de date qui séparent deux instances de date/heure est trop &nbsp; * <br />
* &nbsp; &nbsp; important. Essayez d'utiliser datediff avec une partie de date moins &nbsp; &nbsp;*<br />
* &nbsp; &nbsp; précise. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* PARAMÈTRES EN ENTRÉE : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;@DATEPART CHAR(11) &nbsp; &nbsp; granularité de temps pour calculer la différence &nbsp;*<br />
* &nbsp; &nbsp;@DT1 &nbsp; &nbsp; &nbsp;DATETIME2 &nbsp; &nbsp;date/heure debut &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
* &nbsp; &nbsp;@DT2 &nbsp; &nbsp; &nbsp;DATETIME2 &nbsp; &nbsp;date/heure fin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* <br />
*******************************************************************************<br />
* VALEURS POSSIBLE POUR LE PARAMÈTRE @DATEPART : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;valeures acceptées &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;descriptions &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;------------------------------ &nbsp;---------------------- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;year, &nbsp; &nbsp; &nbsp; &nbsp; yy, &nbsp;yyyy &nbsp; &nbsp; &nbsp; &nbsp; année &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;quarter, &nbsp; &nbsp; &nbsp;qq, &nbsp;q &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;trimestre &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;month, &nbsp; &nbsp; &nbsp; &nbsp;mm, &nbsp;m &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mois &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;dayofyear, &nbsp; &nbsp;dy, &nbsp;y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;jour &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;day, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dd, &nbsp;d &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;jour &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;week, &nbsp; &nbsp; &nbsp; &nbsp; wk, &nbsp;ww &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; semaine &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;hour, &nbsp; &nbsp; &nbsp; &nbsp; hh &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;heures &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;minute, &nbsp; &nbsp; &nbsp; mi, &nbsp;n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minutes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;second, &nbsp; &nbsp; &nbsp; ss, &nbsp;s &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;secondes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;millisecond, &nbsp;ms &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;millisecondes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* VALEUR EN SORTIE : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;type SQL BIGINT &nbsp; &nbsp; &nbsp; &nbsp;nombre d'unité temporelles entre les deux valeurs *<br />
*******************************************************************************<br />
* EXEMPLES D'UTILISATION : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;SELECT dbo.F_DATEDIFF_BIG('minute', '0001-01-01', '9999-12-31') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;--&gt; 5258963520 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;SELECT dbo.F_DATEDIFF_BIG('millisecond', '0001-01-01', '9999-12-31') &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;--&gt; 315537811200000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* LIMITES : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;la granularité est limitée à la milliseconde &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; &nbsp;la validité du calcul est assurée pour la plage des dates ISO SQL : &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; &nbsp;[0001-01-01 00:00:00.0000000, 9999-12-31 23:59:59.9999999] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
******************************************************************************/</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
<span style="color: #808080; font-style: italic;">-- test de validité des paramètres</span><br />
<span style="color: #993333; font-weight: bold;">IF</span> @DT1 <span style="color: #66cc66;">&gt;</span> @DT2 &nbsp;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">NULL</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">SET</span> @DATEPART <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LOWER</span><span style="color: #66cc66;">&#40;</span>@DATEPART<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'year'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'yy'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'yyyy'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'quarter'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; <span style="color: #ff0000;">'qq'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'q'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'month'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'mm'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'m'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'week'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'wk'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ww'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'dayofyear'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff0000;">'dy'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'y'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'day'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'dd'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'d'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'hour'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'hh'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'minute'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'mi'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'n'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'second'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'ss'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'s'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'millisecond'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ms'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">NULL</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- sans conversion primaire :</span><br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'year'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'yy'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'yyyy'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp;@DT1<span style="color: #66cc66;">,</span> @DT2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'quarter'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; <span style="color: #ff0000;">'qq'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'q'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>QUARTER<span style="color: #66cc66;">,</span> @DT1<span style="color: #66cc66;">,</span> @DT2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'month'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'mm'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'m'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">,</span> &nbsp; @DT1<span style="color: #66cc66;">,</span> @DT2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'week'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'wk'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ww'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>WEEK<span style="color: #66cc66;">,</span> &nbsp; &nbsp;@DT1<span style="color: #66cc66;">,</span> @DT2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'dayofyear'</span><span style="color: #66cc66;">,</span> &nbsp; <span style="color: #ff0000;">'dy'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'y'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">'day'</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'dd'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'d'</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> &nbsp; &nbsp; @DT1<span style="color: #66cc66;">,</span> @DT2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- pour les autres cas</span><br />
<br />
<span style="color: #808080; font-style: italic;">-- variable de sortie</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @RETVAL <span style="color: #993333; font-weight: bold;">BIGINT</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- initialisation pour le nombre de jours</span><br />
<span style="color: #993333; font-weight: bold;">SET</span> @RETVAL <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> @DT1<span style="color: #66cc66;">,</span> @DT2<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">BIGINT</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- ajout des parties d'heure si précision heure</span><br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'hour'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'hh'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @RETVAL <span style="color: #66cc66;">=</span> @RETVAL <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #66cc66;">+</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">HOUR</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT1 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT2 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> @RETVAL;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- ajout des parties de minutes si précision minute</span><br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'minute'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'mi'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'n'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @RETVAL <span style="color: #66cc66;">=</span> @RETVAL <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">1440</span> <span style="color: #66cc66;">+</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MINUTE</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT1 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT2 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> @RETVAL;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- ajout des parties de seconde si précision seconde</span><br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'second'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ss'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'s'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @RETVAL <span style="color: #66cc66;">=</span> @RETVAL <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">86400</span> <span style="color: #66cc66;">+</span> DATEDIFF<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SECOND</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT1 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT2 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> @RETVAL;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- ajout des parties de milliseconde si précision milliseconde</span><br />
<span style="color: #993333; font-weight: bold;">IF</span> @DATEPART <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'millisecond'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'ms'</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @RETVAL <span style="color: #66cc66;">=</span> @RETVAL <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">86400000</span> <span style="color: #66cc66;">+</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>millisecond<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT1 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>@DT2 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TIME</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">RETURN</span> @RETVAL;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">NULL</span>;<br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<div id="attachment_590" style="width: 548px" class="wp-caption alignnone"><a href="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg"><img src="http://blog.developpez.com/sqlpro/files/2015/09/Couverture-livre-SQL-server-Eyrolles.jpg" alt="Développez et administrez pour la performance avec SQL Server 2014" width="538" height="652" class="size-full wp-image-590" /></a><p class="wp-caption-text">Développez et administrez pour la performance avec SQL Server 2014</p></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calcules de durée en jour avec des mois comptables  de 30 jours</title>
		<link>https://blog.developpez.com/sqlpro/p12855/langage-sql-norme/calcules-de-duree-en-jour-avec-des-mois-compatbels-de-30-jours</link>
		<comments>https://blog.developpez.com/sqlpro/p12855/langage-sql-norme/calcules-de-duree-en-jour-avec-des-mois-compatbels-de-30-jours#comments</comments>
		<pubDate>Mon, 23 Mar 2015 22:55:56 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[30 jours]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[mois comptable]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=556</guid>
		<description><![CDATA[À la suite d&#8217;une demande du forum, je me suis penché sur le calcul de durée en jour avec des mois comptables de 30 jours. Comme d&#8217;habitude il faut passer par une table de date ! La demande originale est postée ici : www.developpez.net/forums/d1508019/bases-donnees/ms-sql-server/developpement/ Nous sommes partit de la table suivante : CREATE TABLE T_DAT [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>À la suite d&rsquo;une demande du forum, je me suis penché sur le calcul de durée en jour avec des mois comptables de 30 jours. Comme d&rsquo;habitude il faut passer par une table de date !<br />
<span id="more-556"></span><br />
La demande originale est postée ici :<br />
<a href="www.developpez.net/forums/d1508019/bases-donnees/ms-sql-server/developpement/">www.developpez.net/forums/d1508019/bases-donnees/ms-sql-server/developpement/</a></p>
<p>Nous sommes partit de la table suivante :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> T_DAT<br />
<span style="color: #66cc66;">&#40;</span>DAT_DATE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">DATE</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span><br />
&nbsp;DAT_AN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">YEAR</span><span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">SMALLINT</span><span style="color: #66cc66;">&#41;</span> PERSISTED<span style="color: #66cc66;">,</span><br />
&nbsp;DAT_MOIS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MONTH</span><span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TINYINT<span style="color: #66cc66;">&#41;</span> PERSISTED<span style="color: #66cc66;">,</span><br />
&nbsp;DAT_JOUR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TINYINT<span style="color: #66cc66;">&#41;</span> &nbsp; PERSISTED<span style="color: #66cc66;">,</span><br />
&nbsp;DAT_NB_JOUR_FIN_MOIS &nbsp; &nbsp; TINYINT <span style="color: #66cc66;">,</span><br />
&nbsp;DAT_JOUR_FIN_MOIS &nbsp; &nbsp; &nbsp; &nbsp;TINYINT<br />
<span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Que nous avons rempli avec les 3 requêtes suivantes :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SET</span> NOCOUNT <span style="color: #993333; font-weight: bold;">ON</span>;<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @D <span style="color: #993333; font-weight: bold;">DATE</span><br />
<span style="color: #993333; font-weight: bold;">SET</span> @D <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'2000-01-01'</span><br />
WHILE @D <span style="color: #66cc66;">&lt;</span> <span style="color: #ff0000;">'2100-12-31'</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> T_DAT <span style="color: #66cc66;">&#40;</span>DAT_DATE<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span>@D<span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @D <span style="color: #66cc66;">=</span> DATEADD<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> @D<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">END</span>;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">WITH</span> T0 <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #66cc66;">&#40;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> DAT_DATE<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">ROW_NUMBER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span><span style="color: #66cc66;">&#40;</span>PARTITION <span style="color: #993333; font-weight: bold;">BY</span> DAT_AN<span style="color: #66cc66;">,</span> DAT_MOIS <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> DAT_JOUR <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">AS</span> NB_JOUR_FIN_MOIS<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_DAT<br />
<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">UPDATE</span> T<br />
<span style="color: #993333; font-weight: bold;">SET</span> &nbsp; &nbsp;DAT_NB_JOUR_FIN_MOIS <span style="color: #66cc66;">=</span> NB_JOUR_FIN_MOIS<br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_DAT <span style="color: #993333; font-weight: bold;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> T0 <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ON</span> T<span style="color: #66cc66;">.</span>DAT_DATE <span style="color: #66cc66;">=</span> T0<span style="color: #66cc66;">.</span>DAT_DATE;<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<br />
<span style="color: #993333; font-weight: bold;">UPDATE</span> T<br />
<span style="color: #993333; font-weight: bold;">SET</span> &nbsp; &nbsp;DAT_JOUR_FIN_MOIS <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>DAT_JOUR <br />
<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; T_DAT <span style="color: #993333; font-weight: bold;">AS</span> T<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> T_DAT <span style="color: #993333; font-weight: bold;">AS</span> T2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ON</span> T<span style="color: #66cc66;">.</span>DAT_AN <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>DAT_AN<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> &nbsp;T<span style="color: #66cc66;">.</span>DAT_MOIS <span style="color: #66cc66;">=</span> T2<span style="color: #66cc66;">.</span>DAT_MOIS<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">AND</span> T2<span style="color: #66cc66;">.</span>DAT_NB_JOUR_FIN_MOIS <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p>Nous avons ensuite créé la fonction de calcul :</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 F_MOIS30 (@D1 DATE, @D2 DATE)<br />
RETURNS INT<br />
AS<br />
BEGIN<br />
&nbsp; &nbsp;DECLARE @AN INT, @MOIS INT, @JFM INT<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;SELECT @AN = DAT_AN, @MOIS = DAT_MOIS, @JFM = DAT_NB_JOUR_FIN_MOIS<br />
&nbsp; &nbsp;FROM &nbsp; T_DAT <br />
&nbsp; &nbsp;WHERE DAT_DATE = @D1;<br />
<br />
&nbsp; &nbsp;SELECT @AN = DAT_AN - @AN, @MOIS = DAT_MOIS - @MOIS, @JFM = @JFM + DAT_JOUR<br />
&nbsp; &nbsp;FROM &nbsp; T_DAT <br />
&nbsp; &nbsp;WHERE DAT_DATE = @D2;<br />
<br />
&nbsp; &nbsp;RETURN (@AN * 12 + @MOIS - 1) * 30 + @JFM<br />
END;<br />
GO</div></div>
<p>Il ne restait plus qu&#039;à la tester :</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">SELECT dbo.F_MOIS30('2014-03-20', '2015-02-01')</div></div>
<p>Ce qui donne 312 résultat escompté !</p>
<p>CQFD</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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL
Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vider toutes les tables d&#8217;une base</title>
		<link>https://blog.developpez.com/sqlpro/p12679/ms-sql-server/vider-toutes-les-tables-dune-base</link>
		<comments>https://blog.developpez.com/sqlpro/p12679/ms-sql-server/vider-toutes-les-tables-dune-base#comments</comments>
		<pubDate>Tue, 22 Jul 2014 12:08:25 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=492</guid>
		<description><![CDATA[Une question simple et un réponse efficace. Comment vider toutes les tables d&#8217;une base de données ? L&#8217;intégrité référentielle va complexifier la chose car il faudrait faire un DELETE de chaque table en tenant compte de la hiérarchie d&#8217;imbrication des références d&#8217;intégrités du fait des contraintes de clefs étrangères. Mais SQL Server permet de désactiver [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Une question simple et un réponse efficace. Comment vider toutes les tables d&rsquo;une base de données ?<br />
<span id="more-492"></span><br />
L&rsquo;intégrité référentielle va complexifier la chose car il faudrait faire un DELETE de chaque table en tenant compte de la hiérarchie d&rsquo;imbrication des références d&rsquo;intégrités du fait des contraintes de clefs étrangères. Mais SQL Server permet de désactiver les contraintes, ce qui va nous rendre service dans le cas présent.<br />
La solution consiste donc à :<br />
&#8211; désactiver les contraintes FOREIGN KEY<br />
&#8211; lancer un DELETE sur toutes les tables<br />
&#8211; réactiver les contraintes FOREIGN KEY<br />
Voici le script final :</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">DECLARE</span> @<span style="color: #993333; font-weight: bold;">SQL</span> NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">BEGIN</span> <span style="color: #993333; font-weight: bold;">TRANSACTION</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">BEGIN</span> TRY<br />
<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">-- désactivation des contraintes d'intégrité référentielles pour les clefs étrangères</span><br />
<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'ALTER TABLE ['</span> <span style="color: #66cc66;">+</span> TABLE_SCHEMA <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'].['</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'] '</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">' NOCHECK CONSTRAINT ['</span> <span style="color: #66cc66;">+</span> CONSTRAINT_NAME <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'];'</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> INFORMATION_SCHEMA<span style="color: #66cc66;">.</span>TABLE_CONSTRAINTS<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">WHERE</span> CONSTRAINT_TYPE <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">'FOREIGN KEY'</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SET</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">''</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">-- vidage des tables</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'DELETE FROM ['</span> <span style="color: #66cc66;">+</span> TABLE_SCHEMA <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'].['</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'];'</span> <br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> &nbsp; INFORMATION_SCHEMA<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLES</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">WHERE</span> &nbsp;TABLE_TYPE <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'BASE TABLE'</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">-- réactivation des contraintes d'intégrité référentielles pour les clefs étrangères</span><br />
<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">=</span> @<span style="color: #993333; font-weight: bold;">SQL</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'ALTER TABLE ['</span> <span style="color: #66cc66;">+</span> TABLE_SCHEMA <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'].['</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'] WITH CHECK'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">' CHECK CONSTRAINT ['</span> <span style="color: #66cc66;">+</span> CONSTRAINT_NAME <span style="color: #66cc66;">+</span> N<span style="color: #ff0000;">'];'</span><br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">FROM</span> INFORMATION_SCHEMA<span style="color: #66cc66;">.</span>TABLE_CONSTRAINTS<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">WHERE</span> CONSTRAINT_TYPE <span style="color: #66cc66;">=</span> N<span style="color: #ff0000;">'FOREIGN KEY'</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">EXEC</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">SQL</span><span style="color: #66cc66;">&#41;</span>; &nbsp; <br />
<br />
&nbsp; &nbsp;COMMIT <span style="color: #993333; font-weight: bold;">TRANSACTION</span>:<br />
<br />
<span style="color: #993333; font-weight: bold;">END</span> TRY &nbsp; <br />
<span style="color: #993333; font-weight: bold;">BEGIN</span> CATCH<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">ROLLBACK</span>;<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">DECLARE</span> @MSG NVARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1200</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp; &nbsp;RAISERROR <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Transaction annulée suite à erreur dans le script : '</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">16</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> @MSG<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">END</span> CATCH;</div></div>
<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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Format de date SQL Server</title>
		<link>https://blog.developpez.com/sqlpro/p12628/ms-sql-server/format-de-date-sql-server</link>
		<comments>https://blog.developpez.com/sqlpro/p12628/ms-sql-server/format-de-date-sql-server#comments</comments>
		<pubDate>Wed, 28 May 2014 08:39:58 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=465</guid>
		<description><![CDATA[Quel format utiliser pour une date avec SQL Server ? Le format normatif bien sûr ! Le format des dates (exprimées sous forme de chaines de caractères) : La norme SQL impose 2 formats différents pour les dates exprimées sous forme de chaines de caractères : 1) Format ISO court : AAAAMMJJ (aucun séparateur, année [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Quel format utiliser pour une date avec SQL Server ? Le format normatif bien sûr !<br />
<span id="more-465"></span><br />
<strong>Le format des dates (exprimées sous forme de chaines de caractères) :</strong></p>
<p>La norme SQL impose 2 formats différents pour les dates exprimées sous forme de chaines de caractères :<br />
1) <strong>Format ISO court</strong> : <strong>AAAAMMJJ</strong> (aucun séparateur, année en premier sur 4 chiffres, puis mois sur 2 et jour sur 2).<br />
2) <strong>Format ISO long</strong> : <strong>AAAA-MM-JJ</strong> (séparateur le tiret, année en premier sur 4 chiffres, puis mois sur 2 et jour sur 2).<br />
Ce sont les seuls formats de date supportés quelque soit les configurations des serveurs et des sessions.<br />
Mieux vaut donc s&rsquo;en tenir exclusivement à ces deux formats.</p>
<p><strong>Dans quel cas les utiliser ?</strong></p>
<p><strong>1) Format ISO court : DATETIME</strong><br />
<strong>2) Format ISO long : DATETIME2, DATE, DATETIMEOFFSET</strong></p>
<p><strong>Pourquoi ces différences ?</strong> </p>
<p>MS SQL Server essaye de respecter la norme SQL au plus près.<br />
Le format ISO court était le format recommandé par la norme SQL jusqu&rsquo;à la version SQL 2 de 1992. À cette époque SQL Server n&rsquo;avait que le type DATETIME<br />
À partir de la norme SQL de 1999, le format a changé en ISO long. Or comme les types DATETIME2, DATE, DATETIMEOFFSET ont été introduits en 2008 par SQL Server, c&rsquo;est désormais sur le format ISO long que ces nouveaux types reposent.</p>
<p><strong>NOTA</strong> : pour des raisons de précision, il faut <strong>éviter le type DATETIME</strong> et le convertir en DATETIME2. Le type DATETIME étant considéré comme obsolète.</p>
<p><strong>D&rsquo;autres formats ?</strong></p>
<p>Il suffit de le préciser pour votre session par la commande SET DATEFORMAT et il spécifie l&rsquo;ordre des parties de la date. Les paramètres valides sont mdy, dmy, ymd, ydm, myd et dym. Aucun séparateur particulier n&rsquo;est à spécifier car tous sont ignorés. Le système prendra donc en compte uniquement les chiffres, et pour l&rsquo;année, sur 2 ou 4 chiffres. La valeur pivot du siècle étant définie par la configuration du serveur (EXEC sp_configure &lsquo;two digit year cutoff&rsquo;).<br />
La valeur par défaut de ce paramétrage de session étant celle spécifique à la &laquo;&nbsp;langue&nbsp;&raquo; de l&rsquo;utilisateur. Par exemple pour un utilisateur s&rsquo;étant connecté en langue française, la valeur par défaut est dmy.</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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>
<p>L&rsquo;entreprise <a href="http://www.sqlspot.com">SQL Spot</a><br />
<strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a></p>
<p><img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL Server" /></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Procédure de réorganisation du stockage de la base tempdb d’une instance Microsoft SQL Server</title>
		<link>https://blog.developpez.com/sqlpro/p12182/ms-sql-server/procedure-de-reorganisation-du-stockage-de-la-base-tempdb-dune-instance-microsoft-sql-server</link>
		<comments>https://blog.developpez.com/sqlpro/p12182/ms-sql-server/procedure-de-reorganisation-du-stockage-de-la-base-tempdb-dune-instance-microsoft-sql-server#comments</comments>
		<pubDate>Sat, 17 Aug 2013 17:44:18 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=335</guid>
		<description><![CDATA[Cette procédure est destinée à réorganiser le stockage de la base de données système tempdb d’une instance Microsoft SQL Server NOTA : on trouvera une version exempte des erreurs liés au format de publication de développez.com à l&#8217;URL : http://sqlprofessionnal.wordpress.com/2013/08/17/procedure-de-reorganisation-du-stockage-de-la-base-tempdb-dune-instance-microsoft-sql-server/ USE msdb; GO IF OBJECT_ID('dbo.P_MOVE_TEMPDB_FILES') IS NOT NULL &#160; &#160;EXEC ('DROP PROCEDURE dbo.P_MOVE_TEMPDB_FILES '); GO [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Cette procédure est destinée à réorganiser le stockage de la base de données système tempdb d’une instance Microsoft SQL Server</p>
<p><span id="more-335"></span></p>
<p>NOTA : on trouvera une version exempte des erreurs liés au format de publication de développez.com à l&rsquo;URL :<br />
<a href="http://sqlprofessionnal.wordpress.com/2013/08/17/procedure-de-reorganisation-du-stockage-de-la-base-tempdb-dune-instance-microsoft-sql-server/">http://sqlprofessionnal.wordpress.com/2013/08/17/procedure-de-reorganisation-du-stockage-de-la-base-tempdb-dune-instance-microsoft-sql-server/</a></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 />
<br />
IF OBJECT_ID('dbo.P_MOVE_TEMPDB_FILES') IS NOT NULL<br />
&nbsp; &nbsp;EXEC ('DROP PROCEDURE dbo.P_MOVE_TEMPDB_FILES ');<br />
GO &nbsp; &nbsp;<br />
<br />
CREATE PROCEDURE dbo.P_MOVE_TEMPDB_FILES <br />
&nbsp; &nbsp; &nbsp; &nbsp;@NBR_FICHIER &nbsp;TINYINT, &nbsp; &nbsp; &nbsp; -- nombre de fichiers de données à créer<br />
&nbsp; &nbsp; &nbsp; &nbsp;@DEST_DATA &nbsp; &nbsp;NVARCHAR(256), -- répertoire destination des données<br />
&nbsp; &nbsp; &nbsp; &nbsp;@SIZE_DATA_GB SMALLINT, &nbsp; &nbsp; &nbsp;-- taille des fichiers de données en Go<br />
&nbsp; &nbsp; &nbsp; &nbsp;@DEST_TRAN &nbsp; &nbsp;NVARCHAR(128), -- répertoire destination des transactions<br />
&nbsp; &nbsp; &nbsp; &nbsp;@SIZE_TRAN_GB SMALLINT, &nbsp; &nbsp; &nbsp;-- taille du journal de transaction en Go<br />
&nbsp; &nbsp; &nbsp; &nbsp;@GROWTH_MB &nbsp; &nbsp;TINYINT &nbsp; &nbsp; &nbsp; &nbsp;-- pas d'incrément des fichiers en Mo<br />
AS<br />
/****************************************************************************** <br />
* Procédure modifiant le stockage des fichiers de la base système tempdb &nbsp; &nbsp; &nbsp;*<br />
******************************************************************************* <br />
* Fred. Brouard - http://sqlpro.developpez.com - www.sqlspot.com - 2013-08-16 *<br />
******************************************************************************* <br />
* Cette procédure permet de redessiner le stockage de la BD système tempdb &nbsp; &nbsp;* <br />
* FONCTIONNEMENT : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* après avoir vérifié les paramètres, la procédure modifie l'organisation du &nbsp;*<br />
* stockage de la base tempdb et fournit un script pour supprimer les fichiers *<br />
* obsolètes. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* PARAMÈTRES : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* @NBR_FICHIER &nbsp;: nombre de fichiers de données à créer &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; * <br />
* @DEST_DATA &nbsp; &nbsp;: répertoire de destination des fichiers de données &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* @SIZE_DATA_GB : taille des fichiers de données en Go &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
* @DEST_TRAN &nbsp; &nbsp;: répertoire de destination du journal de transaction &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* @SIZE_DATA_GB : taille du journal de transaction en Go &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* @GROWTH_MB &nbsp; &nbsp;: taile en Mo du pas d'incrément de tous les fichiers &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* PROBLÈMES POSSIBLES : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* - l'utilisateur qui lance cette procédure n'a pas les privilèges adéquats &nbsp; *<br />
* - le compte de service de l'instance SQL Server n'a pas les droits en &nbsp; &nbsp; &nbsp; * <br />
* &nbsp; lecture/ecriture sur le répertoire de destination &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* - le répertoire de destination n'a pas une capacité suffisante pour y &nbsp; &nbsp; &nbsp; *<br />
* &nbsp; stocker les fichiers à déplacer &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* - des fichiers possédant le même nom sont déjà en exploitation dans la &nbsp; &nbsp; &nbsp;*<br />
* &nbsp; destination<br />
* REMÈDE : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* en cas d'erreur, le résultat (paneau messages de SSMS) fournit la commande &nbsp;*<br />
* qui est partie en exception, mais aussi toute la partie déjà exécutée du &nbsp; &nbsp;*<br />
* script de migration. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
******************************************************************************/ <br />
BEGIN<br />
-- variables locales<br />
DECLARE @N TABLE (N TINYINT);<br />
DECLARE @T TABLE (existe BIT, repertoire BIT, parent BIT);<br />
DECLARE @F TABLE (nom_logique &nbsp;sysname,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nom_physique NVARCHAR(384),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nature &nbsp; &nbsp; &nbsp; CHAR(4),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;action&quot; &nbsp; &nbsp; CHAR(6),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;destination &nbsp;NVARCHAR(384),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;taille_GO &nbsp; &nbsp;SMALLINT); <br />
DECLARE @U TABLE (unite CHAR(1), capacite INT); -- capacité de stockage actuelle &nbsp;<br />
DECLARE @D TABLE (unite CHAR(1), capacite INT); -- volume à stocké<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
DECLARE @SQL NVARCHAR(max), @SCRIPT NVARCHAR(max), @ERROR NVARCHAR(102);<br />
<br />
-- initialisations diverses<br />
SELECT @SIZE_DATA_GB = COALESCE(@SIZE_DATA_GB, 0), <br />
&nbsp; &nbsp; &nbsp; &nbsp;@SIZE_TRAN_GB = COALESCE(@SIZE_TRAN_GB, 0);<br />
INSERT INTO @N VALUES (0), (1), (2), (3);<br />
INSERT INTO @N<br />
SELECT T1.N + T2.N * 4 +T3.N * 16<br />
FROM &nbsp; @N AS T1<br />
&nbsp; &nbsp; &nbsp; &nbsp;CROSS JOIN @N AS T2<br />
&nbsp; &nbsp; &nbsp; &nbsp;CROSS JOIN @N AS T3<br />
WHERE &nbsp;T1.N + T2.N * 4 +T3.N * 16 &amp;gt; 3;<br />
UPDATE @N SET N = N + 1; <br />
<br />
-- vérifications diverses :<br />
IF @NBR_FICHIER = 0 OR @NBR_FICHIER IS NULL<br />
BEGIN<br />
&nbsp; &nbsp;RAISERROR('Le nombre de fichiers à spécifier pour les données doit être &amp;gt; 0.', <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16, 1); <br />
&nbsp; &nbsp;RETURN;<br />
END;<br />
IF @NBR_FICHIER &amp;gt; 64<br />
BEGIN<br />
&nbsp; &nbsp;RAISERROR('Le nombre de fichiers pour les données (%d) est trop élevé.', <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16, 1); <br />
&nbsp; &nbsp;RETURN;<br />
END;<br />
IF @SIZE_DATA_GB &amp;lt; 1 <br />
BEGIN<br />
&nbsp; &nbsp;RAISERROR(&amp;#039;la taille spécifieé %d pour les données est incorrecte.&amp;#039;, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16, 1, @SIZE_DATA_GB); <br />
&nbsp; &nbsp;RETURN;<br />
END;<br />
IF @SIZE_TRAN_GB &amp;lt; 1 <br />
BEGIN<br />
&nbsp; &nbsp;RAISERROR(&amp;#039;la taille spécifieé %d pour les transactions est incorrecte.&amp;#039;, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16, 1, @SIZE_TRAN_GB); <br />
&nbsp; &nbsp;RETURN;<br />
END; <br />
<br />
-- les destinations sont-elles bien des répertoires ?<br />
IF RIGHT(@DEST_DATA, 1) &nbsp;'\'<br />
&nbsp; &nbsp;SET @DEST_DATA = @DEST_DATA + N'\';<br />
SET @SQL = 'EXEC sys.xp_fileexist ''' + @DEST_DATA +''';'<br />
INSERT INTO @T EXEC (@SQL);<br />
IF NOT EXISTS(SELECT * FROM @T WHERE repertoire = 1)<br />
BEGIN<br />
&nbsp; &nbsp;RAISERROR('L''emplacement %s n''est pas un répertoire de données.', <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16, 1, @DEST_DATA); <br />
&nbsp; &nbsp;RETURN;<br />
END; <br />
DELETE FROM @T;<br />
IF RIGHT(@DEST_TRAN, 1) &nbsp;'\'<br />
&nbsp; &nbsp;SET @DEST_TRAN = @DEST_TRAN + N'\';<br />
SET @SQL = 'EXEC sys.xp_fileexist ''' + @DEST_TRAN +''';'<br />
INSERT INTO @T EXEC (@SQL);<br />
IF NOT EXISTS(SELECT * FROM @T WHERE repertoire = 1)<br />
BEGIN<br />
&nbsp; &nbsp;RAISERROR('L''emplacement %s n''est pas un répertoire de données.', <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16, 1, @DEST_TRAN); <br />
&nbsp; &nbsp;RETURN;<br />
END; &nbsp;<br />
-- y a t-il la capacité de stockage ?<br />
INSERT INTO @U<br />
EXEC ('EXEC xp_fixeddrives;');<br />
INSERT INTO @D SELECT LEFT(@DEST_DATA, 1), @NBR_FICHIER * @SIZE_DATA_GB * 1024;<br />
IF LEFT(@DEST_DATA, 1) = LEFT(@DEST_TRAN, 1)<br />
&nbsp; &nbsp;UPDATE @D<br />
&nbsp; &nbsp;SET capacite = capacite + @SIZE_TRAN_GB * 1024<br />
&nbsp; &nbsp;WHERE unite = LEFT(@DEST_TRAN, 1)<br />
ELSE<br />
&nbsp; &nbsp;INSERT INTO @D SELECT LEFT(@DEST_TRAN, 1), @SIZE_TRAN_GB * 1024;<br />
SET @ERROR = N'';<br />
SELECT @ERROR = @ERROR + N' '<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + CAST((D.capacite - U.capacite) / 1024.0 AS NVARCHAR(32))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + N' Go dans l''unité ' + U.unite + N', ' <br />
FROM &nbsp; @U AS U<br />
&nbsp; &nbsp; &nbsp; &nbsp;INNER JOIN @D AS D<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ON U.unite = D.unite<br />
WHERE &nbsp;U.capacite &amp;lt; D.capacite;<br />
IF @ERROR &nbsp;N''<br />
BEGIN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;SET @ERROR = N'Il manque ' + SUBSTRING(@ERROR, 1, LEN(@ERROR) - 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + N' pour assurer la capacité de stockage demandée.';<br />
&nbsp; &nbsp;RAISERROR(@ERROR, 16, 1, @DEST_TRAN); <br />
&nbsp; &nbsp;RETURN; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
END;<br />
-- la procédure xp_cmdshell est-elle utilisable ?<br />
IF NOT EXISTS(SELECT * FROM sys.configurations <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE name = 'xp_cmdshell' AND value_in_use = 1)<br />
BEGIN<br />
&nbsp; &nbsp;RAISERROR('La procédure xp_cmdshell nécessaire à l''utilisation <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;de cette procédure est désactivée. Veuillez contacter <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;votre adminisrateur de bases de données', 16, 1);<br />
&nbsp; &nbsp;RETURN;<br />
END; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;<br />
-- on stocke les matadonnées de redéfinition du stockage dans @F<br />
-- fichier à modifier : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
INSERT INTO @F<br />
SELECT name, physical_name, type_desc, 'MODIFY', <br />
&nbsp; &nbsp; &nbsp; &nbsp;CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN &quot;type&quot; = 0 THEN @DEST_DATA <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN &quot;type&quot; = 1 THEN @DEST_TRAN<br />
&nbsp; &nbsp; &nbsp; &nbsp;END + REVERSE(SUBSTRING(REVERSE(physical_name), 1 , &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CHARINDEX('\', REVERSE(physical_name)) &nbsp;-1)),<br />
&nbsp; &nbsp; &nbsp; &nbsp;CASE <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN &quot;type&quot; = 0 THEN @SIZE_DATA_GB <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN &quot;type&quot; = 1 THEN @SIZE_TRAN_GB<br />
&nbsp; &nbsp; &nbsp; &nbsp;END &nbsp; <br />
FROM &nbsp; sys.master_files AS f<br />
WHERE &nbsp;DB_NAME(database_id) = 'tempdb'<br />
&nbsp; AND &nbsp;file_id &nbsp;2; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
-- fichiers de données à créer :<br />
INSERT INTO @F<br />
SELECT 'tempdata' + CAST(N AS VARCHAR(2)), &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp;'ROWS', 'ADD',<br />
&nbsp; &nbsp; &nbsp; &nbsp;@DEST_DATA + 'tempdata' + CAST(N AS VARCHAR(2)) + '.ndf',<br />
&nbsp; &nbsp; &nbsp; &nbsp;@SIZE_DATA_GB<br />
FROM &nbsp; @N <br />
WHERE &nbsp;N BETWEEN 1 AND @NBR_FICHIER - 1;<br />
<br />
SET @SCRIPT = N'';<br />
-- construction du script de modification du stockage de tempdb<br />
BEGIN TRY<br />
&nbsp; &nbsp;-- fichiers à modifier<br />
&nbsp; &nbsp;SET @SQL = N'';<br />
&nbsp; &nbsp;SELECT @SQL = @SQL + N'ALTER DATABASE tempdb MODIFY FILE ( NAME = ''' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ nom_logique + N''', FILENAME = ''' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ destination + N''', SIZE = ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ CAST(taille_GO AS VARCHAR(16)) + N' GB, FILEGROWTH = ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ CAST(@GROWTH_MB AS VARCHAR(16)) + N' MB);' <br />
&nbsp; &nbsp;FROM &nbsp; @F<br />
&nbsp; &nbsp;WHERE &nbsp;&quot;action&quot; = 'MODIFY'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;EXEC (@SQL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;SET @SCRIPT = @SCRIPT + @SQL + NCHAR(13) + NCHAR(10) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ N'GO' + NCHAR(13) + NCHAR(10);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;-- fichiers à supprimer<br />
&nbsp; &nbsp;SET @SQL = N'';<br />
&nbsp; &nbsp;SELECT @SQL = @SQL + N'ALTER DATABASE tempdb REMOVE FILE [' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ nom_logique + N'];' <br />
&nbsp; &nbsp;FROM &nbsp; @F<br />
&nbsp; &nbsp;WHERE &nbsp;&quot;action&quot; = 'REMOVE'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;EXEC (@SQL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;SET @SCRIPT = @SCRIPT + @SQL + NCHAR(13) + NCHAR(10) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ N'GO' + NCHAR(13) + NCHAR(10);<br />
&nbsp; &nbsp;EXEC (@SQL);<br />
&nbsp; &nbsp;SET @SCRIPT = @SCRIPT + @SQL + NCHAR(13) + NCHAR(10) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ N'GO' + NCHAR(13) + NCHAR(10);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp;-- fichiers à ajouter<br />
&nbsp; &nbsp;SET @SQL = N'';<br />
&nbsp; &nbsp;SELECT @SQL = @SQL + N'ALTER DATABASE tempdb ADD FILE ( NAME = ''' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ nom_logique + N''', FILENAME = ''' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ destination + N''', SIZE = ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ CAST(taille_GO AS VARCHAR(16)) + N' GB, FILEGROWTH = ' <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ CAST(@GROWTH_MB AS VARCHAR(16)) + N' MB);' <br />
&nbsp; &nbsp;FROM &nbsp; @F<br />
&nbsp; &nbsp;WHERE &nbsp;&quot;action&quot; = 'ADD'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;EXEC (@SQL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;SET @SCRIPT = @SCRIPT + @SQL + NCHAR(13) + NCHAR(10) <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+ N'GO' + NCHAR(13) + NCHAR(10);<br />
&nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp;-- tout s'est bien passé, on informe des fichiers à nettoyer<br />
&nbsp; &nbsp;SELECT nom_physique AS FICHIER_A_SUPPRIMER,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'EXEC xp_cmdshell ''DEL &quot;' + nom_physique +'&quot;'';'<br />
&nbsp; &nbsp;FROM &nbsp; @F <br />
&nbsp; &nbsp;WHERE &nbsp;nom_physique IS NOT NULL <br />
&nbsp; &nbsp; &nbsp;AND &nbsp;nom_physique &nbsp;destination; &nbsp; &nbsp; <br />
END TRY<br />
-- en cas d'ereur...<br />
BEGIN CATCH<br />
&nbsp; &nbsp;SET @ERROR = ERROR_MESSAGE();<br />
&nbsp; &nbsp;RAISERROR('Une erreur est survenur lors de la procédure dbo.P_MOVE_TEMPDB_FILES .', 16, 1);<br />
-- renseigne sur la commande ayant levée l'exception<br />
&nbsp; &nbsp;RAISERROR('L''ereur est survenue lors de la commande : %s', 16, 1, @SQL);<br />
-- renvoie la partie du script déjà exécutée<br />
&nbsp; &nbsp;RAISERROR(@ERROR, 16, 1);<br />
&nbsp; &nbsp;PRINT '--- PARTIE DU SCRIPT DÉJÀ EXÉCUTÉE ---';<br />
&nbsp; &nbsp;PRINT @SCRIPT; &nbsp; <br />
END CATCH<br />
END;<br />
GO</div></div>
<p><strong>Exemple d&rsquo;utilisation :</strong></p>
<p>EXEC msdb.dbo.P_MOVE_TEMPDB_FILES<br />
     @NBR_FICHIER  = 4 ,             &#8212; nombre de fichiers de données à créer<br />
     @DEST_DATA    = &lsquo;D:\DATABASES\SQL2008R2&prime;, &#8212; répertoire destination des données<br />
     @SIZE_DATA_GB = 16,             &#8212; taille des fichiers de données en Go<br />
     @DEST_TRAN    = &lsquo;E:\DATABASES\SQL2008R2&prime;, &#8212; répertoire destination des transactions<br />
     @SIZE_TRAN_GB = 10,             &#8212; taille du journal de transaction en Go<br />
     @GROWTH_MB    = 100             &#8212; pas d&rsquo;incrément des fichiers en Mo</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Algorithme de placement optimal d&#8217;une ressource, compte tenu de la distance et de la population cible (Dijkstra)</title>
		<link>https://blog.developpez.com/sqlpro/p12031/langage-sql-norme/dijkstra</link>
		<comments>https://blog.developpez.com/sqlpro/p12031/langage-sql-norme/dijkstra#comments</comments>
		<pubDate>Fri, 24 May 2013 15:07:16 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2012]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=289</guid>
		<description><![CDATA[La recherche d&#8217;un placement optimal sur un graphe composé de nœuds et d&#8217;arcs est similaire à un calcul de plus court chemin mais doit prendre en considération des poids supplémentaires, ici, la population de chaque nœud. L&#8217;ensemble est réalisé par des procédures Transact SQL dans une base dédiée à ce type de calcul pour MS [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>La recherche d&rsquo;un placement optimal sur un graphe composé de nœuds et d&rsquo;arcs est similaire à un calcul de plus court chemin mais doit prendre en considération des poids supplémentaires, ici, la population de chaque nœud. L&rsquo;ensemble est réalisé par des procédures Transact SQL dans une base dédiée à ce type de calcul pour MS SQL Server (toutes versions depuis 2000).<br />
<span id="more-289"></span><br />
Cette méthode est basée sur les procédures de plus court chemin écrites par l&rsquo;utilisateur <a href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=77262" title="Plus court chemin avec Dijkstra en Transact SQL pour MS SQL Server" target="_blank">SwePeso sur sqlteam.com</a> et utilise l&rsquo;algorithme de Dijkstra.<br />
Cette solution originale a été proposée par Evan Barke dans le forum consacré à MS SQL Server :<br />
<a href="http://www.developpez.net/forums/d1346509/" target="_blank">http://www.developpez.net/forums/d1346509/</a></p>
<p><strong>CRÉATION DE LA BASE DE DONNÉES</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">/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* CRÉATION DE LA BASE DE DONNÉES &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/<br />
CREATE DATABASE DB_DIJKSTRA<br />
GO<br />
<br />
ALTER DATABASE DB_DIJKSTRA SET RECOVERY SIMPLE;<br />
GO<br />
<br />
DECLARE @SQL NVARCHAR(max);<br />
SELECT @SQL = COALESCE(@SQL, '') + <br />
&nbsp; &nbsp; &nbsp; &nbsp;CASE &quot;type&quot; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 0 THEN'ALTER DATABASE DB_DIJKSTRA MODIFY FILE (NAME = ''' + name +''', SIZE = 250 MB);'<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN 1 THEN'ALTER DATABASE DB_DIJKSTRA MODIFY FILE (NAME = ''' + name +''', SIZE = &nbsp;50 MB);'<br />
&nbsp; &nbsp; &nbsp; &nbsp;END &nbsp; <br />
FROM &nbsp; sys.master_files<br />
WHERE &nbsp;name = 'DB_DIJKSTRA';<br />
EXEC (@SQL);<br />
<br />
USE DB_DIJKSTRA<br />
GO</div></div>
<p><strong>CRÉATION DES TABLES DE TRAVAIL :</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">/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* CRÉATION DES TABLES DE TRAVAIL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/<br />
CREATE TABLE Nodes (<br />
&nbsp; &nbsp; &nbsp; &nbsp;NodeID &nbsp; &nbsp; &nbsp;BIGINT IDENTITY (1, 1) NOT NULL PRIMARY KEY,<br />
&nbsp; &nbsp; &nbsp; &nbsp;NodeName &nbsp; &nbsp;NVARCHAR(64) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOT NULL ,<br />
&nbsp; &nbsp; &nbsp; &nbsp;Cost &nbsp; &nbsp; &nbsp; &nbsp;FLOAT,<br />
&nbsp; &nbsp; &nbsp; &nbsp;PathID &nbsp; &nbsp; &nbsp;BIGINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp;Calculated &nbsp;BIT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NOT NULL DEFAULT 0,<br />
&nbsp; &nbsp; &nbsp; &nbsp;Population &nbsp;FLOAT,<br />
&nbsp; &nbsp; &nbsp; &nbsp;Score &nbsp; &nbsp; &nbsp; FLOAT<br />
) <br />
GO<br />
<br />
CREATE TABLE Paths (<br />
&nbsp; &nbsp; &nbsp; &nbsp;PathID &nbsp; &nbsp; &nbsp;BIGINT IDENTITY (1, 1) NOT NULL PRIMARY KEY,<br />
&nbsp; &nbsp; &nbsp; &nbsp;FromNodeID &nbsp;BIGINT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOT NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOREIGN KEY REFERENCES Nodes (NodeID),<br />
&nbsp; &nbsp; &nbsp; &nbsp;ToNodeID &nbsp; &nbsp;BIGINT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOT NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOREIGN KEY REFERENCES Nodes (NodeID),<br />
&nbsp; &nbsp; &nbsp; &nbsp;Cost &nbsp; &nbsp; &nbsp; &nbsp;FLOAT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NOT NULL<br />
);<br />
GO<br />
<br />
CREATE TABLE PathsMatrix (<br />
&nbsp; &nbsp; &nbsp; &nbsp;MatPathID &nbsp; BIGINT IDENTITY (1, 1) NOT NULL PRIMARY KEY,<br />
&nbsp; &nbsp; &nbsp; &nbsp;FromNodeID &nbsp;BIGINT NOT NULL ,<br />
&nbsp; &nbsp; &nbsp; &nbsp;ToNodeID &nbsp; &nbsp;BIGINT NOT NULL ,<br />
&nbsp; &nbsp; &nbsp; &nbsp;Cost &nbsp; &nbsp; &nbsp; &nbsp;FLOAT &nbsp;NULL<br />
);<br />
GO</div></div>
<p><strong>PROCÉDURE DE VIDAGE ET REMISE À ZÉRO AUTO INCRÉMENT :</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">CREATE PROCEDURE uspDijkstraInitializeMap<br />
<br />
AS<br />
/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* PROCÉDURE DE VIDAGE ET REMISE À ZÉRO AUTO INCRÉMENT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/<br />
SET NOCOUNT ON;<br />
<br />
DELETE FROM Paths;<br />
<br />
DBCC CHECKIDENT (Paths, RESEED, 0);<br />
<br />
DELETE FROM Nodes;<br />
<br />
DBCC CHECKIDENT (Nodes, RESEED, 0);<br />
<br />
GO</div></div>
<p><strong>PROCÉDURE D&rsquo;AJOUT D&rsquo;UN CHEMIN :</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">CREATE PROCEDURE uspDijkstraAddPath<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@FromNodeName NVARCHAR(64),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@ToNodeName &nbsp; NVARCHAR(64),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@Cost &nbsp; &nbsp; &nbsp; &nbsp; FLOAT<br />
AS<br />
/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* PROCÉDURE D'AJOUT D'UN CHEMIN &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/<br />
SET NOCOUNT ON;<br />
<br />
DECLARE @FromNodeID BIGINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @ToNodeID &nbsp; BIGINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @PathID &nbsp; &nbsp; BIGINT;<br />
<br />
SELECT @FromNodeID = NodeID<br />
FROM &nbsp; Nodes<br />
WHERE &nbsp;NodeName = @FromNodeName;<br />
&nbsp;<br />
IF @FromNodeID IS NULL<br />
BEGIN<br />
<br />
&nbsp; &nbsp;INSERT &nbsp;Nodes (NodeName, &nbsp; &nbsp; &nbsp;Calculated)<br />
&nbsp; &nbsp;VALUES &nbsp; &nbsp; &nbsp; &nbsp;(@FromNodeName, 0);<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;SELECT @FromNodeID = SCOPE_IDENTITY();<br />
&nbsp; &nbsp;<br />
END;<br />
&nbsp;<br />
SELECT @ToNodeID = NodeID<br />
FROM &nbsp; Nodes<br />
WHERE &nbsp;NodeName = @ToNodeName;<br />
<br />
IF @ToNodeID IS NULL<br />
BEGIN<br />
<br />
&nbsp; &nbsp;INSERT Nodes (NodeName, &nbsp; &nbsp;Calculated)<br />
&nbsp; &nbsp;VALUES &nbsp; &nbsp; &nbsp; (@ToNodeName, 0);<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;SELECT @ToNodeID = SCOPE_IDENTITY();<br />
&nbsp; &nbsp;<br />
END<br />
&nbsp;<br />
SELECT @PathID = PathID<br />
FROM &nbsp; Paths<br />
WHERE &nbsp;FromNodeID = @FromNodeID<br />
&nbsp; AND &nbsp;ToNodeID = @ToNodeID;<br />
&nbsp;<br />
IF @PathID IS NULL<br />
<br />
&nbsp; &nbsp;INSERT Paths (FromNodeID, ToNodeID, Cost)<br />
&nbsp; &nbsp;VALUES (@FromNodeID, @ToNodeID, @Cost);<br />
&nbsp; &nbsp;<br />
ELSE<br />
<br />
&nbsp; &nbsp;UPDATE Paths<br />
&nbsp; &nbsp;SET &nbsp; &nbsp;Cost = @Cost<br />
&nbsp; &nbsp;WHERE &nbsp;FromNodeID = @FromNodeID<br />
&nbsp; &nbsp; &nbsp;AND &nbsp;ToNodeID = @ToNodeID;<br />
GO</div></div>
<p><strong>PROCÉDURE DE RÉINITIALISATION DU CALCUL DE COUT :</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 dbo.uspDijkstraClearMap<br />
AS<br />
/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* PROCÉDURE DE RÉINITIALISATION DU CALCUL DE COUT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/<br />
SET NOCOUNT ON;<br />
&nbsp;<br />
UPDATE Nodes<br />
SET &nbsp; &nbsp;PathID = NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp;Cost = NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp;Calculated = 0;<br />
GO</div></div>
<p><strong>PROCÉDURE DE CALCUL DE MOINDRE COUT ENTRE DEUX NŒUDS :</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">CREATE PROCEDURE uspDijkstraResolve<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@FromNodeName NVARCHAR(64),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@ToNodeName &nbsp; NVARCHAR(64)<br />
AS<br />
/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* PROCÉDURE DE CALCUL DE MOINDRE COUT ENTRE DEUX NŒUDS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/<br />
SET NOCOUNT ON;<br />
&nbsp;<br />
INSERT INTO PathsMatrix (FromNodeID, ToNodeID)<br />
VALUES &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((SELECT NodeID <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; Nodes <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;NodeName = @FromNodeName) , <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(SELECT NodeID <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; Nodes <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;NodeName = @ToNodeName));<br />
&nbsp;<br />
DECLARE @MatPathID &nbsp;BIGINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @FromNodeID BIGINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @ToNodeID &nbsp; BIGINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @NodeID &nbsp; &nbsp; BIGINT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @Cost &nbsp; &nbsp; &nbsp; FLOAT,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @PathID &nbsp; &nbsp; BIGINT;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
DECLARE @Map TABLE (RowID &nbsp; &nbsp; &nbsp; &nbsp;BIGINT IDENTITY(-1, -1),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FromNodeName NVARCHAR(64),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ToNodeName &nbsp; NVARCHAR(64),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Cost &nbsp; &nbsp; &nbsp; &nbsp; FLOAT); <br />
<br />
SELECT TOP 1 @MatPathID = MatPathID <br />
FROM &nbsp; PathsMatrix <br />
ORDER &nbsp;BY MatPathID DESC;<br />
&nbsp;<br />
EXEC uspDijkstraClearMap;<br />
&nbsp;<br />
SELECT @FromNodeID = NodeID,<br />
&nbsp; &nbsp; &nbsp; &nbsp;@NodeID = NodeID<br />
FROM &nbsp; Nodes<br />
WHERE &nbsp;NodeName = @FromNodeName;<br />
&nbsp;<br />
IF @FromNodeID IS NULL<br />
BEGIN<br />
&nbsp; &nbsp;SELECT @FromNodeName = COALESCE(@FromNodeName, '');<br />
&nbsp; &nbsp;RAISERROR ('From node name ''%s'' can not be found.', 16, 1, @FromNodeName);<br />
&nbsp; &nbsp;RETURN;<br />
END<br />
&nbsp;<br />
SELECT @ToNodeID = NodeID<br />
FROM &nbsp; Nodes<br />
WHERE &nbsp;NodeName = @ToNodeName;<br />
&nbsp;<br />
IF @ToNodeID IS NULL<br />
BEGIN<br />
&nbsp; &nbsp;SELECT @ToNodeName = COALESCE(@ToNodeName, '');<br />
&nbsp; &nbsp;RAISERROR ('To node name ''%s'' can not be found.', 16, 1, @ToNodeName);<br />
&nbsp; &nbsp;RETURN;<br />
END<br />
&nbsp;<br />
UPDATE Nodes<br />
SET &nbsp; &nbsp;Cost = 0<br />
WHERE &nbsp;NodeID = @FromNodeID;<br />
&nbsp;<br />
WHILE @NodeID IS NOT NULL<br />
BEGIN<br />
<br />
&nbsp; &nbsp;UPDATE ToNodes<br />
&nbsp; &nbsp;SET &nbsp; &nbsp;ToNodes.Cost = CASE<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN ToNodes.Cost IS NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;THEN FromNodes.Cost + Paths.Cost<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHEN FromNodes.Cost + Paths.Cost &amp;lt; ToNodes.Cost <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;THEN FromNodes.Cost + Paths.Cost<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE ToNodes.Cost<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ToNodes.PathID = Paths.PathID<br />
&nbsp; &nbsp;FROM &nbsp; &nbsp; &nbsp; &nbsp; Nodes AS FromNodes<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN Paths <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON Paths.FromNodeID = FromNodes.NodeID<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN Nodes AS ToNodes <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON ToNodes.NodeID = Paths.ToNodeID<br />
&nbsp; &nbsp;WHERE &nbsp;FromNodes.NodeID = @NodeID<br />
&nbsp; &nbsp; &nbsp;AND &nbsp;(ToNodes.Cost IS NULL OR FromNodes.Cost + Paths.Cost &amp;lt; ToNodes.Cost)<br />
&nbsp; &nbsp; &nbsp;AND &nbsp;ToNodes.Calculated = 0;<br />
&nbsp;<br />
&nbsp; &nbsp;UPDATE FromNodes<br />
&nbsp; &nbsp;SET &nbsp; &nbsp;FromNodes.Calculated = 1<br />
&nbsp; &nbsp;FROM &nbsp; Nodes AS FromNodes<br />
&nbsp; &nbsp;WHERE &nbsp;FromNodes.NodeID = @NodeID;<br />
&nbsp;<br />
&nbsp; &nbsp;SELECT @NodeID = NULL;<br />
&nbsp;<br />
&nbsp; &nbsp;SELECT TOP 1 @NodeID = Nodes.NodeID<br />
&nbsp; &nbsp;FROM &nbsp; Nodes<br />
&nbsp; &nbsp;WHERE &nbsp;Nodes.Calculated = 0<br />
&nbsp; &nbsp; &nbsp;AND &nbsp;Nodes.Cost IS NOT NULL<br />
&nbsp; &nbsp;ORDER &nbsp;BY Nodes.Cost;<br />
END<br />
&nbsp;<br />
IF EXISTS (SELECT NULL <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; Nodes <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE &nbsp;NodeID = @ToNodeID <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND &nbsp;Cost IS NULL)<br />
BEGIN<br />
&nbsp; &nbsp;SELECT FromNodeName, ToNodeName, Cost <br />
&nbsp; &nbsp;FROM &nbsp; @Map;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;RETURN;<br />
END<br />
&nbsp;<br />
WHILE @FromNodeID &nbsp;@ToNodeID<br />
BEGIN<br />
&nbsp; &nbsp;SELECT @FromNodeName = FromNodes.NodeName,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ToNodeName = ToNodes.NodeName,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Cost = ToNodes.Cost,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @PathID = ToNodes.PathID<br />
&nbsp; &nbsp;FROM &nbsp; Nodes AS ToNodes<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN Paths <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON Paths.PathID = ToNodes.PathID<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN Nodes AS FromNodes <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON FromNodes.NodeID = Paths.FromNodeID<br />
&nbsp; &nbsp;WHERE &nbsp;ToNodes.NodeID = @ToNodeID;<br />
&nbsp;<br />
&nbsp; &nbsp;INSERT @Map (FromNodeName, &nbsp;ToNodeName, &nbsp;Cost)<br />
&nbsp; &nbsp;VALUES &nbsp; &nbsp; &nbsp;(@FromNodeName, @ToNodeName, @Cost);<br />
&nbsp;<br />
&nbsp; &nbsp;SELECT @ToNodeID = Paths.FromNodeID<br />
&nbsp; &nbsp;FROM &nbsp; Paths<br />
&nbsp; &nbsp;WHERE &nbsp;Paths.PathID = @PathID;<br />
&nbsp; &nbsp;<br />
END;<br />
<br />
UPDATE PathsMatrix<br />
SET &nbsp; &nbsp;Cost = (SELECT MAX(Cost) FROM @Map)<br />
WHERE &nbsp;MatPathID = @MatPathID;<br />
&nbsp;<br />
GO</div></div>
<p><strong>PROCÉDURE DE GÉNÉRATION DE LA MATRICE DES CHEMINS :</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">CREATE PROCEDURE dbo.uspDijkstraCreateMatrix<br />
/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* PROCÉDURE DE GÉNÉRATION DE LA MATRICE DES CHEMINS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/ <br />
AS<br />
&nbsp;<br />
SET NOCOUNT ON;<br />
&nbsp;<br />
IF EXISTS (SELECT 1 FROM PathsMatrix)<br />
&nbsp; &nbsp;TRUNCATE TABLE &nbsp;PathsMatrix;<br />
&nbsp;<br />
DECLARE @FROM NVARCHAR(64),<br />
&nbsp; &nbsp; &nbsp; &nbsp; @TO &nbsp; NVARCHAR(64);<br />
&nbsp;<br />
DECLARE cursorNodes CURSOR &nbsp;<br />
LOCAL FORWARD_ONLY STATIC READ_ONLY <br />
FOR <br />
&nbsp; &nbsp;SELECT FromNode.NodeName, ToNode.NodeName<br />
&nbsp; &nbsp;FROM &nbsp; Nodes AS FromNode<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CROSS JOIN Nodes AS ToNode<br />
&nbsp; &nbsp;WHERE &nbsp;FromNode.NodeName &nbsp;ToNode.NodeName;<br />
&nbsp;<br />
OPEN cursorNodes;<br />
<br />
FETCH cursorNodes INTO @FROM, @TO;<br />
&nbsp;<br />
WHILE @@FETCH_STATUS = 0<br />
BEGIN<br />
<br />
&nbsp; &nbsp;EXEC dbo.uspDijkstraResolve <br />
&nbsp; &nbsp; &nbsp; &nbsp; @FromNodeName = @FROM,<br />
&nbsp; &nbsp; &nbsp; &nbsp; @ToNodeName = @TO;<br />
&nbsp;<br />
&nbsp; &nbsp;FETCH cursorNodes INTO @FROM, @TO<br />
END<br />
&nbsp;<br />
CLOSE cursorNodes;<br />
DEALLOCATE cursorNodes;<br />
<br />
GO</div></div>
<p><strong>PROCÉDURE DE CALCUL DU PLACEMENT OPTIMAL :</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">CREATE PROCEDURE dbo.uspDijkstraCalculateOptimal<br />
AS<br />
/******************************************************************************<br />
* ALGORITHME DE DIJKSTRA : recherche d'un placement optimal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
*******************************************************************************<br />
* PROCÉDURE DE CALCUL DU PLACEMENT OPTIMAL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
*******************************************************************************<br />
* Solution originale d'Evan Barke :http://www.developpez.net/forums/d1346509/ *<br />
******************************************************************************/ <br />
SET NOCOUNT ON; <br />
&nbsp;<br />
DECLARE @FromNodeID NVARCHAR(64);<br />
&nbsp;<br />
DECLARE cursorNodes CURSOR<br />
LOCAL FORWARD_ONLY STATIC READ_ONLY <br />
FOR<br />
&nbsp; &nbsp;SELECT FromNode.NodeID<br />
&nbsp; &nbsp;FROM Nodes AS FromNode;<br />
&nbsp;<br />
OPEN cursorNodes;<br />
<br />
FETCH cursorNodes INTO @FromNodeID;<br />
&nbsp;<br />
WHILE @@FETCH_STATUS = 0<br />
BEGIN<br />
<br />
&nbsp; &nbsp;UPDATE Nodes SET Score = (SELECT SUM((N.Population)*P.Cost)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; Nodes N<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; INNER JOIN PathsMatrix P <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON P.FromNodeID = N.NodeID<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHERE N.NodeID = @FromNodeID) <br />
&nbsp; &nbsp;WHERE Nodes.NodeID = @FromNodeID;<br />
&nbsp;<br />
&nbsp; &nbsp;FETCH cursorNodes INTO @FromNodeID;<br />
&nbsp;<br />
END<br />
&nbsp;<br />
CLOSE cursorNodes;<br />
<br />
DEALLOCATE cursorNodes;<br />
&nbsp;<br />
SELECT NodeName, Score<br />
FROM &nbsp; Nodes<br />
ORDER &nbsp;BY Score DESC;<br />
&nbsp;<br />
GO</div></div>
<p><strong>EXEMPLE :</strong></p>
<p>Notre ami Evan, vivant dans le sud à décider d&rsquo;implanter sa cabane entre les vignobles de muscat (Lunel) et la mer (La Grande Motte) afin d&rsquo;y vendre des peaux de kangourou&#8230; Quel sera le meilleur placement entre toutes ces villes compte tenu des distances et de la population ?</p>
<p><strong>Phase 1 :</strong><em> initialisons les tables des nœuds et arcs</em></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 dbo.uspDijkstraInitializeMap;</div></div>
<p><strong>Phase 2 :</strong> <em>création des nœuds et arcs</em></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">EXEC dbo.uspDijkstraAddPath 'Mauguio', 'St Aunès', 2;<br />
EXEC dbo.uspDijkstraAddPath 'St Aunès', 'Mauguio', 2;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'Mauguio', 'Mudaison', 3;<br />
EXEC dbo.uspDijkstraAddPath 'Mudaison', 'Mauguio', 3;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'Mauguio', 'Candillargues', 6;<br />
EXEC dbo.uspDijkstraAddPath 'Candillargues', 'Mauguio', 6;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'Mauguio', 'La Grande Motte', 4;<br />
EXEC dbo.uspDijkstraAddPath 'La Grande Motte', 'Mauguio', 4;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'Mauguio', 'Pérols', 6;<br />
EXEC dbo.uspDijkstraAddPath 'Pérols', 'Mauguio', 6;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'Candillargues', 'Lansargues', 3;<br />
EXEC dbo.uspDijkstraAddPath 'Lansargues', 'Candillargues', 3;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'Lansargues', 'St Just', 4;<br />
EXEC dbo.uspDijkstraAddPath 'St Just', 'Lansargues', 4;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'St Just', 'Lunel', 7;<br />
EXEC dbo.uspDijkstraAddPath 'Lunel', 'St Just', 7;<br />
&nbsp;<br />
EXEC dbo.uspDijkstraAddPath 'Pérols', 'Lattes', 6;<br />
EXEC dbo.uspDijkstraAddPath 'Lattes', 'Pérols', 6;</div></div>
<p><strong>Phase 3 : </strong><em>création de la matrice des distances</em></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 dbo.uspDijkstraCreateMatrix;</div></div>
<p><strong>Phase 4 : </strong><em>pondération par la population</em></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">UPDATE Nodes SET Population = 16307 WHERE NodeName = 'Mauguio';<br />
UPDATE Nodes SET Population = &nbsp;3041 WHERE NodeName = 'St Aunès';<br />
UPDATE Nodes SET Population = &nbsp;2498 WHERE NodeName = 'Mudaison';<br />
UPDATE Nodes SET Population = &nbsp;1401 WHERE NodeName = 'Candillargues';<br />
UPDATE Nodes SET Population = &nbsp;8440 WHERE NodeName = 'La Grande Motte';<br />
UPDATE Nodes SET Population = &nbsp;8509 WHERE NodeName = 'Pérols';<br />
UPDATE Nodes SET Population = &nbsp;2744 WHERE NodeName = 'Lansargues';<br />
UPDATE Nodes SET Population = &nbsp;2851 WHERE NodeName = 'St Just';<br />
UPDATE Nodes SET Population = 25277 WHERE NodeName = 'Lunel';<br />
UPDATE Nodes SET Population = 15927 WHERE NodeName = 'Lattes';</div></div>
<p><strong>Phase 5 : </strong><em>calcul du placement optimal</em></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 dbo.uspDijkstraCalculateOptimal;</div></div>
<p><strong>RÉSULTAT :</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">NodeName &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Score<br />
----------------- ---------<br />
Lunel &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4524583<br />
Lattes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2532393<br />
Mauguio &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1223025<br />
Pérols &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 944499<br />
La Grande Motte &nbsp; &nbsp;903080<br />
St Just &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;350673<br />
St Aunès &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 276731<br />
Lansargues &nbsp; &nbsp; &nbsp; &nbsp; 271656<br />
Mudaison &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 247302<br />
Candillargues &nbsp; &nbsp; &nbsp;121887</div></div>
<p>Il semble que le vignoble de Lunel soit plus attirant que la mer bleu de la grande Motte !</p>
<p><strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a><br />
<img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL Server" /></p>
<pre>

<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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>

</pre>
<p>L&rsquo;ntreprise <a href="http://www.sqlspot.com">SQL Spot</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ajout du niveau dans un arbre intervallaire</title>
		<link>https://blog.developpez.com/sqlpro/p11924/langage-sql-norme/ajout-du-niveau-dans-un-arbre-intervallaire</link>
		<comments>https://blog.developpez.com/sqlpro/p11924/langage-sql-norme/ajout-du-niveau-dans-un-arbre-intervallaire#comments</comments>
		<pubDate>Wed, 17 Apr 2013 16:36:53 +0000</pubDate>
		<dc:creator><![CDATA[SQLpro]]></dc:creator>
				<category><![CDATA[bases de données]]></category>
		<category><![CDATA[Langage SQL (norme)]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[PostGreSQL]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[arborescence]]></category>
		<category><![CDATA[arbre]]></category>
		<category><![CDATA[intervallaire]]></category>
		<category><![CDATA[intervalle]]></category>
		<category><![CDATA[niveau]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/sqlpro/?p=281</guid>
		<description><![CDATA[Voici comment ajouter le niveau des éléments dans un arbre modélisé par intervalles. Pour notre test, la table est la suivante : CREATE TABLE T_VEHICULE_VHC (VHC_ID &#160; &#160; &#160; &#160; INTEGER NOT NULL PRIMARY KEY, &#160;VHC_BG &#160; &#160; &#160; &#160; INTEGER, &#160;VHC_BD &#160; &#160; &#160; &#160; INTEGER, &#160;VHC_NOM &#160; &#160; &#160; &#160;VARCHAR(16)); Les données que [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Voici comment ajouter le niveau des éléments dans un arbre modélisé par intervalles.<br />
<span id="more-281"></span><br />
Pour notre test, la table est la suivante :</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 TABLE T_VEHICULE_VHC<br />
(VHC_ID &nbsp; &nbsp; &nbsp; &nbsp; INTEGER NOT NULL PRIMARY KEY,<br />
&nbsp;VHC_BG &nbsp; &nbsp; &nbsp; &nbsp; INTEGER,<br />
&nbsp;VHC_BD &nbsp; &nbsp; &nbsp; &nbsp; INTEGER,<br />
&nbsp;VHC_NOM &nbsp; &nbsp; &nbsp; &nbsp;VARCHAR(16));</div></div>
<p>Les données que l&rsquo;on y insère sont les suivantes :</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">INSERT INTO T_VEHICULE_VHC VALUES (1, 1, 26, 'ALL');<br />
INSERT INTO T_VEHICULE_VHC VALUES (2, 2, 7, 'SEA');<br />
INSERT INTO T_VEHICULE_VHC VALUES (3, 8, 19, 'EARTH');<br />
INSERT INTO T_VEHICULE_VHC VALUES (4, 20, 25, 'AIR');<br />
INSERT INTO T_VEHICULE_VHC VALUES (5, 3, 4, 'SUBMARINE');<br />
INSERT INTO T_VEHICULE_VHC VALUES (6, 5, 6, 'BOAT');<br />
INSERT INTO T_VEHICULE_VHC VALUES (7, 9, 10, 'CAR');<br />
INSERT INTO T_VEHICULE_VHC VALUES (8, 11, 16, 'TWO WHEELS');<br />
INSERT INTO T_VEHICULE_VHC VALUES (9, 17, 18, 'TRUCK');<br />
INSERT INTO T_VEHICULE_VHC VALUES (10, 21, 22, 'ROCKET');<br />
INSERT INTO T_VEHICULE_VHC VALUES (11, 23, 24, 'PLANE');<br />
INSERT INTO T_VEHICULE_VHC VALUES (12, 12, 13, 'MOTORCYCLE');<br />
INSERT INTO T_VEHICULE_VHC VALUES (13, 14, 15, 'BICYCLE');;</div></div>
<p>Que l&rsquo;on peut présenter ainsi :</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">VHC_NOM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VHC_ID &nbsp; &nbsp; &nbsp;VHC_NIVEAU &nbsp;VHC_PATH<br />
------------------ ----------- ----------- --------------------------------<br />
ALL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp;AIR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AIR<br />
&nbsp; PLANE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;11 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AIR, PLANE<br />
&nbsp; ROCKET &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AIR, ROCKET<br />
&nbsp;EARTH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EARTH<br />
&nbsp; CAR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EARTH, CAR<br />
&nbsp; TRUCK &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EARTH, TRUCK<br />
&nbsp; TWO WHEELS &nbsp; &nbsp; &nbsp; 8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EARTH, TWO WHEELS<br />
&nbsp; &nbsp;BICYCLE &nbsp; &nbsp; &nbsp; &nbsp; 13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EARTH, TWO WHEELS, BICYCLE<br />
&nbsp; &nbsp;MOTORCYCLE &nbsp; &nbsp; &nbsp;12 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EARTH, TWO WHEELS, MOTORCYCLE<br />
&nbsp;SEA &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SEA<br />
&nbsp; BOAT &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SEA, BOAT<br />
&nbsp; SUBMARINE &nbsp; &nbsp; &nbsp; &nbsp;5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SEA, SUBMARINE</div></div>
<p>Le calcul du niveau peut se faire par la requête :</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">SELECT VHC_ID, <br />
&nbsp; &nbsp; &nbsp; &nbsp;(SELECT COUNT(*) <br />
&nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; T_VEHICULE_VHC <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;VHC_BG &nbsp;REF.VHC_BD) AS VHC_NIVEAU,<br />
&nbsp; &nbsp; &nbsp; &nbsp;VHC_NOM <br />
FROM &nbsp; T_VEHICULE_VHC AS REF;</div></div>
<p>En fait il s&rsquo;agit de compter le nombre de parents d&rsquo;un nœud.</p>
<p>Pour rajouter le calcul du niveau en dur dans la table, on peut faire comme ceci :</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">ALTER TABLE T_VEHICULE_VHC ADD VHC_NIVEAU SMALLINT;</div></div>
<p>Ce qui rajoute la colonne niveau dans la table.</p>
<p>Il faut maintenant la mettre à jour :</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">UPDATE REF<br />
SET &nbsp; &nbsp;VHC_NIVEAU = (SELECT COUNT(*) <br />
&nbsp; &nbsp; &nbsp; &nbsp; FROM &nbsp; T_VEHICULE_VHC <br />
&nbsp; &nbsp; &nbsp; &nbsp; WHERE &nbsp;VHC_BG &nbsp;REF.VHC_BD)<br />
FROM &nbsp; T_VEHICULE_VHC AS REF;</div></div>
<p><strong>Le site web sur le </strong><a href="http://sqlpro.developpez.com/">SQL et les SGBDR</a><br />
<img src="http://blog.developpez.com/media/Microsoft_MVP_logo_vertical Brouard 400.jpg" width="400" height="135" alt="MVP Microsoft SQL Server" /></p>
<pre>

<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">Frédéric Brouard, alias SQLpro, ARCHITECTE DE DONNÉES<br />
Expert &nbsp;S.G.B.D &nbsp;relationnelles &nbsp; et &nbsp; langage &nbsp;S.Q.L<br />
Moste &nbsp;Valuable &nbsp;Professionnal &nbsp;Microsoft &nbsp;SQL Server<br />
Société SQLspot &nbsp;: &nbsp;modélisation, conseil, formation,<br />
optimisation, &nbsp;audit, &nbsp;tuning, &nbsp;administration &nbsp;SGBDR<br />
Enseignant: CNAM PACA, ISEN Toulon, CESI Aix en Prov.</div></div>

</pre>
<p>L&rsquo;ntreprise <a href="http://www.sqlspot.com">SQL Spot</a></p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
