<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>some thoughts... - Development|T-SQL</title>
    <link>http://www.fits-consulting.de/blog/</link>
    <description>IT makes the world go round - and sometimes stops it...</description>
    <language>en-us</language>
    <copyright>Markus Fischer</copyright>
    <lastBuildDate>Mon, 24 Sep 2007 18:38:48 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>blog@fits-consulting.de</managingEditor>
    <webMaster>blog@fits-consulting.de</webMaster>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=89aec356-0a0b-4083-a2a3-8c847e1e2159</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,89aec356-0a0b-4083-a2a3-8c847e1e2159.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,89aec356-0a0b-4083-a2a3-8c847e1e2159.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=89aec356-0a0b-4083-a2a3-8c847e1e2159</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you would like to split values from a column which are divideable beacause they
are using the same delimiter like an ',' for example you could use the function below.
The function also brings up the postion, which sometimes could be very usefull, too.
</p>
        <p>
To call the function just use,
</p>
        <pre class="csharpcode">
          <span class="kwrd">select</span> * <span class="kwrd">from</span> dbo.fn_split(<span class="str">'Value
1,Value 2'</span>,<span class="str">','</span>)</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
the first parameter is the column to split, the second contains the delimiter. You
can not use different delimiters at one time at the moment, if you want to suggest
some enhancements, please use the comments.... :-)<br />
The statement will bring up the following result set:
</p>
        <p>
          <a href="http://www.fits-consulting.de/blog/content/binary/WindowsLiveWriter/littleSQLhelperssplitacolumn_11473/sql_result%5B2%5D.jpg" atomicselection="true">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="105" src="http://www.fits-consulting.de/blog/content/binary/WindowsLiveWriter/littleSQLhelperssplitacolumn_11473/sql_result_thumb.jpg" width="200" border="0" />
          </a>
        </p>
        <pre class="csharpcode">
          <span class="kwrd">CREATE</span>
          <span class="kwrd">FUNCTION</span> [dbo].[fn_Split](@text
nvarchar(<span class="kwrd">max</span>), @delimiter <span class="kwrd">char</span>(1)
= <span class="str">' '</span>) <span class="kwrd">RETURNS</span> @Strings <span class="kwrd">TABLE</span> ( <span class="kwrd">position</span><span class="kwrd">int</span><span class="kwrd">IDENTITY</span><span class="kwrd">PRIMARY</span><span class="kwrd">KEY</span>, <span class="kwrd">value</span> nvarchar(<span class="kwrd">max</span>)
) <span class="kwrd">AS</span><span class="kwrd">BEGIN</span><span class="kwrd">DECLARE</span> @<span class="kwrd">index</span><span class="kwrd">int</span><span class="kwrd">SET</span> @<span class="kwrd">index</span> =
-1 <span class="kwrd">WHILE</span> (LEN(@text) &gt; 0) <span class="kwrd">BEGIN</span><span class="kwrd">SET</span> @<span class="kwrd">index</span> =
CHARINDEX(@delimiter , @text) <span class="kwrd">IF</span> (@<span class="kwrd">index</span> =
0) <span class="kwrd">AND</span> (LEN(@text) &gt; 0) <span class="kwrd">BEGIN</span> INSERT <span class="kwrd">INTO</span> @Strings <span class="kwrd">VALUES</span> (@text) <span class="kwrd">BREAK</span><span class="kwrd">END</span><span class="kwrd">IF</span> (@<span class="kwrd">index</span> &gt;
1) <span class="kwrd">BEGIN</span> INSERT <span class="kwrd">INTO</span> @Strings <span class="kwrd">VALUES</span> (<span class="kwrd">LEFT</span>(@text,
@<span class="kwrd">index</span> - 1)) <span class="kwrd">SET</span> @text = <span class="kwrd">RIGHT</span>(@text,
(LEN(@text) - @<span class="kwrd">index</span>)) <span class="kwrd">END</span><span class="kwrd">ELSE</span><span class="kwrd">SET</span> @text
= <span class="kwrd">RIGHT</span>(@text, (LEN(@text) - @<span class="kwrd">index</span>)) <span class="kwrd">END</span><span class="kwrd">RETURN</span> END</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=89aec356-0a0b-4083-a2a3-8c847e1e2159" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>little SQL-helpers: split a column</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,89aec356-0a0b-4083-a2a3-8c847e1e2159.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,89aec356-0a0b-4083-a2a3-8c847e1e2159.aspx</link>
      <pubDate>Mon, 24 Sep 2007 18:38:48 GMT</pubDate>
      <description>&lt;p&gt;
If you would like to split values from a column which are divideable beacause they
are using the same delimiter like an ',' for example you could use the function below.
The function also brings up the postion, which sometimes could be very usefull, too.
&lt;/p&gt;
&lt;p&gt;
To call the function just use,
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; * &lt;span class="kwrd"&gt;from&lt;/span&gt; dbo.fn_split(&lt;span class="str"&gt;'Value
1,Value 2'&lt;/span&gt;,&lt;span class="str"&gt;','&lt;/span&gt;)&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
the first parameter is the column to split, the second contains the delimiter. You
can not use different delimiters at one time at the moment, if you want to suggest
some enhancements, please use the comments.... :-)&lt;br&gt;
The&amp;nbsp;statement will bring up the following result set:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.fits-consulting.de/blog/content/binary/WindowsLiveWriter/littleSQLhelperssplitacolumn_11473/sql_result%5B2%5D.jpg" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="105" src="http://www.fits-consulting.de/blog/content/binary/WindowsLiveWriter/littleSQLhelperssplitacolumn_11473/sql_result_thumb.jpg" width="200" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;FUNCTION&lt;/span&gt; [dbo].[fn_Split](@text
nvarchar(&lt;span class="kwrd"&gt;max&lt;/span&gt;), @delimiter &lt;span class="kwrd"&gt;char&lt;/span&gt;(1)
= &lt;span class="str"&gt;' '&lt;/span&gt;) &lt;span class="kwrd"&gt;RETURNS&lt;/span&gt; @Strings &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; ( &lt;span class="kwrd"&gt;position&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt; &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt;, &lt;span class="kwrd"&gt;value&lt;/span&gt; nvarchar(&lt;span class="kwrd"&gt;max&lt;/span&gt;)
) &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @&lt;span class="kwrd"&gt;index&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; @&lt;span class="kwrd"&gt;index&lt;/span&gt; =
-1 &lt;span class="kwrd"&gt;WHILE&lt;/span&gt; (LEN(@text) &amp;gt; 0) &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; @&lt;span class="kwrd"&gt;index&lt;/span&gt; =
CHARINDEX(@delimiter , @text) &lt;span class="kwrd"&gt;IF&lt;/span&gt; (@&lt;span class="kwrd"&gt;index&lt;/span&gt; =
0) &lt;span class="kwrd"&gt;AND&lt;/span&gt; (LEN(@text) &amp;gt; 0) &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; @Strings &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (@text) &lt;span class="kwrd"&gt;BREAK&lt;/span&gt; &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;IF&lt;/span&gt; (@&lt;span class="kwrd"&gt;index&lt;/span&gt; &amp;gt;
1) &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; @Strings &lt;span class="kwrd"&gt;VALUES&lt;/span&gt; (&lt;span class="kwrd"&gt;LEFT&lt;/span&gt;(@text,
@&lt;span class="kwrd"&gt;index&lt;/span&gt; - 1)) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @text = &lt;span class="kwrd"&gt;RIGHT&lt;/span&gt;(@text,
(LEN(@text) - @&lt;span class="kwrd"&gt;index&lt;/span&gt;)) &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;ELSE&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; @text
= &lt;span class="kwrd"&gt;RIGHT&lt;/span&gt;(@text, (LEN(@text) - @&lt;span class="kwrd"&gt;index&lt;/span&gt;)) &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;RETURN&lt;/span&gt; END&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=89aec356-0a0b-4083-a2a3-8c847e1e2159" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,89aec356-0a0b-4083-a2a3-8c847e1e2159.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=ee700f2f-1af6-4526-ad65-d84524eb5526</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,ee700f2f-1af6-4526-ad65-d84524eb5526.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,ee700f2f-1af6-4526-ad65-d84524eb5526.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=ee700f2f-1af6-4526-ad65-d84524eb5526</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Are you also always looking in the BOL if you have to deal with datetime?
</p>
        <p>
This stored procedure could bring some light in the dark...
</p>
        <p>
You will have to call it with the following statement:
</p>
        <pre class="csharpcode">
          <span class="kwrd">Select</span> dbo.fn_formatdate(getdate(),<span class="str">'formated
date: \TT\MM\YYYY \hh:\mi:\ss \ms Week: \wk Weekday: \DW Quarter: \qq'</span>),getdate()</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
The formatstring can contain severall formatstrings and will bring up all datetimeparts
you want, including some additional textparts...
</p>
        <p>
 
</p>
        <pre class="csharpcode">
          <span class="kwrd">CREATE</span>
          <span class="kwrd">FUNCTION</span> [dbo].[fn_formatdate](@dat
datetime,@format <span class="kwrd">varchar</span>(255)) <span class="kwrd">RETURNS</span><span class="kwrd">varchar</span>(255) <span class="kwrd">AS</span><span class="kwrd">BEGIN</span><span class="kwrd">declare</span> @ret <span class="kwrd">varchar</span>(255) <span class="kwrd">declare</span> @i <span class="kwrd">int</span><span class="rem">--
year 4 digits</span><span class="kwrd">set</span> @ret=replace(@format,<span class="str">'\jjjj'</span>,<span class="kwrd">cast</span>(<span class="kwrd">year</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(4))) <span class="rem">--
year 4 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\yyyy'</span>,<span class="kwrd">cast</span>(<span class="kwrd">year</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(4))) <span class="rem">--
day 2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\dd'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(<span class="kwrd">day</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
weekday 1 digit </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\dw'</span>,<span class="kwrd">cast</span>(datepart(dw,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(1))) <span class="rem">--
day of year</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\dy'</span>,<span class="kwrd">right</span>(<span class="str">'00'</span>+<span class="kwrd">cast</span>(<span class="kwrd">day</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(3)),3)) <span class="rem">--
hour 2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\hh'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(datepart(hh,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
year 2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\jj'</span>,<span class="kwrd">right</span>(<span class="kwrd">cast</span>(<span class="kwrd">year</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(4)),2)) <span class="rem">--
minute 2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\mi'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(datepart(mi,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
month 2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\mm'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(<span class="kwrd">month</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
milliseconds 3 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\ms'</span>,<span class="kwrd">right</span>(<span class="str">'00'</span>+<span class="kwrd">cast</span>(datepart(ss,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(3)),3)) <span class="rem">--
quarter 2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\qq'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(datepart(qq,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
seconds 2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\ss'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(datepart(ss,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
day 2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\tt'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(<span class="kwrd">day</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
week 2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\wk'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(datepart(wk,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
year 2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\yy'</span>,<span class="kwrd">right</span>(<span class="kwrd">cast</span>(<span class="kwrd">year</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(4)),2)) <span class="rem">--
day 1-2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\d'</span>,<span class="kwrd">cast</span>(<span class="kwrd">day</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2))) <span class="rem">--
hour 1-2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\h'</span>,<span class="kwrd">cast</span>(datepart(hh,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2))) <span class="rem">--
month 1-2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\m'</span>,<span class="kwrd">cast</span>(<span class="kwrd">month</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2))) <span class="rem">--
minute 2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\n'</span>,<span class="kwrd">right</span>(<span class="str">'0'</span>+<span class="kwrd">cast</span>(datepart(mi,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2)),2)) <span class="rem">--
quarter 1 digit </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\q'</span>,<span class="kwrd">cast</span>(datepart(qq,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(1))) <span class="rem">--
seconds 1-2 digits</span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\s'</span>,<span class="kwrd">cast</span>(datepart(ss,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2))) <span class="rem">--
day 1-2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\t'</span>,<span class="kwrd">cast</span>(<span class="kwrd">day</span>(@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2))) <span class="rem">--
week 1-2 digits </span><span class="kwrd">set</span> @ret=replace(@ret,<span class="str">'\w'</span>,<span class="kwrd">cast</span>(datepart(wk,@dat) <span class="kwrd">as</span><span class="kwrd">varchar</span>(2))) <span class="kwrd">return</span> @ret <span class="kwrd">END</span> GO</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=ee700f2f-1af6-4526-ad65-d84524eb5526" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>little SQL-helpers: help with date formats</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,ee700f2f-1af6-4526-ad65-d84524eb5526.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,ee700f2f-1af6-4526-ad65-d84524eb5526.aspx</link>
      <pubDate>Mon, 24 Sep 2007 16:33:12 GMT</pubDate>
      <description>&lt;p&gt;
Are you also always looking in the BOL if you have to deal with datetime?
&lt;/p&gt;
&lt;p&gt;
This stored procedure could bring some light in the dark...
&lt;/p&gt;
&lt;p&gt;
You will have to call it with the following statement:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Select&lt;/span&gt; dbo.fn_formatdate(getdate(),&lt;span class="str"&gt;'formated
date: \TT\MM\YYYY \hh:\mi:\ss \ms Week: \wk Weekday: \DW Quarter: \qq'&lt;/span&gt;),getdate()&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
The formatstring can contain severall formatstrings and will bring up all datetimeparts
you want, including some additional textparts...
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;FUNCTION&lt;/span&gt; [dbo].[fn_formatdate](@dat
datetime,@format &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(255)) &lt;span class="kwrd"&gt;RETURNS&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(255) &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;declare&lt;/span&gt; @ret &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(255) &lt;span class="kwrd"&gt;declare&lt;/span&gt; @i &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="rem"&gt;--
year 4 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@format,&lt;span class="str"&gt;'\jjjj'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;year&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(4))) &lt;span class="rem"&gt;--
year 4 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\yyyy'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;year&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(4))) &lt;span class="rem"&gt;--
day 2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\dd'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;day&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
weekday 1 digit &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\dw'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(dw,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(1))) &lt;span class="rem"&gt;--
day of year&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\dy'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'00'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;day&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(3)),3)) &lt;span class="rem"&gt;--
hour 2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\hh'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(hh,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
year 2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\jj'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;year&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(4)),2)) &lt;span class="rem"&gt;--
minute 2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\mi'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(mi,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
month 2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\mm'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;month&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
milliseconds 3 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\ms'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'00'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(ss,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(3)),3)) &lt;span class="rem"&gt;--
quarter 2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\qq'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(qq,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
seconds 2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\ss'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(ss,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
day 2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\tt'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;day&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
week 2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\wk'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(wk,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
year 2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\yy'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;year&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(4)),2)) &lt;span class="rem"&gt;--
day 1-2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\d'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;day&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2))) &lt;span class="rem"&gt;--
hour 1-2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\h'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(hh,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2))) &lt;span class="rem"&gt;--
month 1-2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\m'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;month&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2))) &lt;span class="rem"&gt;--
minute 2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\n'&lt;/span&gt;,&lt;span class="kwrd"&gt;right&lt;/span&gt;(&lt;span class="str"&gt;'0'&lt;/span&gt;+&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(mi,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2)),2)) &lt;span class="rem"&gt;--
quarter 1 digit &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\q'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(qq,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(1))) &lt;span class="rem"&gt;--
seconds 1-2 digits&lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\s'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(ss,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2))) &lt;span class="rem"&gt;--
day 1-2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\t'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(&lt;span class="kwrd"&gt;day&lt;/span&gt;(@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2))) &lt;span class="rem"&gt;--
week 1-2 digits &lt;/span&gt; &lt;span class="kwrd"&gt;set&lt;/span&gt; @ret=replace(@ret,&lt;span class="str"&gt;'\w'&lt;/span&gt;,&lt;span class="kwrd"&gt;cast&lt;/span&gt;(datepart(wk,@dat) &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(2))) &lt;span class="kwrd"&gt;return&lt;/span&gt; @ret &lt;span class="kwrd"&gt;END&lt;/span&gt; GO&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=ee700f2f-1af6-4526-ad65-d84524eb5526" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,ee700f2f-1af6-4526-ad65-d84524eb5526.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=0bde9a5a-4f77-4a6d-9310-59a194c1db7c</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,0bde9a5a-4f77-4a6d-9310-59a194c1db7c.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,0bde9a5a-4f77-4a6d-9310-59a194c1db7c.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0bde9a5a-4f77-4a6d-9310-59a194c1db7c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Do you want to create database snapshots? And do you want to do it programmatically?
Then you could use this stored procedure...
</p>
        <p>
Enjoy!
</p>
        <pre class="csharpcode">
          <span class="kwrd">CREATE</span>
          <span class="kwrd">PROC</span> [dbo].[spr_CreateSnapshot]
(@Masterdb <span class="kwrd">VARCHAR</span>(255), @SnapshotName <span class="kwrd">VARCHAR</span>(255),
@<span class="kwrd">Execute</span><span class="kwrd">BIT</span> = 1) <span class="kwrd">AS</span><span class="kwrd">SET</span> NOCOUNT <span class="kwrd">ON</span><span class="kwrd">DECLARE</span> @NewLine <span class="kwrd">CHAR</span>(2) <span class="kwrd">DECLARE</span> @Q <span class="kwrd">CHAR</span>(1) <span class="kwrd">DECLARE</span> @fname <span class="kwrd">VARCHAR</span>(255) <span class="kwrd">DECLARE</span> @extention <span class="kwrd">VARCHAR</span>(255) <span class="kwrd">DECLARE</span> @Pfad <span class="kwrd">VARCHAR</span>(255) <span class="kwrd">DECLARE</span> @DBname <span class="kwrd">VARCHAR</span>(255) <span class="kwrd">DECLARE</span> @LogicName <span class="kwrd">VARCHAR</span>(255) <span class="kwrd">DECLARE</span> @Command <span class="kwrd">VARCHAR</span>(<span class="kwrd">MAX</span>) <span class="kwrd">DECLARE</span> @indexExt <span class="kwrd">INT</span><span class="kwrd">DECLARE</span> @indexPfad <span class="kwrd">INT</span><span class="kwrd">DECLARE</span> @lenFname <span class="kwrd">INT</span><span class="kwrd">DECLARE</span> @lenPfad <span class="kwrd">INT</span><span class="kwrd">DECLARE</span> @lenDB <span class="kwrd">INT</span><span class="kwrd">DECLARE</span> @lenExt <span class="kwrd">INT</span><span class="kwrd">CREATE</span><span class="kwrd">TABLE</span> #Info
(physical_name <span class="kwrd">VARCHAR</span>(255) <span class="kwrd">not</span><span class="kwrd">null</span>,
logicname <span class="kwrd">VARCHAR</span>(255) <span class="kwrd">not</span><span class="kwrd">null</span>) <span class="kwrd">SET</span> @newLine
= <span class="kwrd">CHAR</span>(13) + <span class="kwrd">CHAR</span>(10) <span class="kwrd">SET</span> @Q
= <span class="kwrd">CHAR</span>(39) <span class="kwrd">SET</span> @command = <span class="str">'INSERT
INTO #info (physical_name, logicname) SELECT s.physical_name,s.[name] AS LogicName
FROM '</span> + Quotename(@masterdb) + <span class="str">'.sys.filegroups as g INNER
JOIN sys.master_files AS s ON s.type = 0 AND s.database_id = db_id('</span> + @Q +
@Masterdb + @Q + <span class="str">') AND s.drop_lsn is null AND s.data_space_id =
g.data_space_id ORDER BY g.data_space_id'</span><span class="kwrd">EXECUTE</span> (@Command) <span class="kwrd">SET</span> @Command
= <span class="str">'CREATE DATABASE '</span> + @SnapshotName + @NewLine <span class="kwrd">SET</span> @Command
= @Command + <span class="str">'ON'</span> + @NewLine <span class="kwrd">DECLARE</span> c <span class="kwrd">CURSOR</span> READ_ONLY <span class="kwrd">FOR</span><span class="kwrd">SELECT</span> physical_name,
logicname <span class="kwrd">FROM</span> #info <span class="kwrd">OPEN</span> c <span class="kwrd">FETCH</span><span class="kwrd">NEXT</span><span class="kwrd">FROM</span> c <span class="kwrd">INTO</span> @fname,@LogicName <span class="kwrd">WHILE</span> (@@fetch_status
&lt;&gt; -1) <span class="kwrd">BEGIN</span><span class="kwrd">IF</span> (@@fetch_status
&lt;&gt; -2) <span class="kwrd">BEGIN</span><span class="kwrd">SET</span> @fname
= REVERSE(@fname) <span class="kwrd">SET</span> @lenFname = LEN(@fname) <span class="kwrd">SET</span> @indexExt
= CHARINDEX(<span class="str">'.'</span>,@fname) -1 <span class="kwrd">SET</span> @indexPfad
= CHARINDEX(<span class="str">'\'</span>,@fname) - 1 <span class="kwrd">SET</span> @extention
= REVERSE(<span class="kwrd">SUBSTRING</span> (@fname, 1, @indexExt)) <span class="kwrd">SET</span> @lenExt
= LEN(@extention) <span class="kwrd">SET</span> @Pfad = <span class="kwrd">LEFT</span> (REVERSE(@fname),
@lenFname - @indexPfad) <span class="kwrd">SET</span> @lenPfad = LEN(@Pfad) <span class="kwrd">SET</span> @DBname
= <span class="kwrd">SUBSTRING</span>(REVERSE(@fname), @lenPfad + 1, (@lenFname -
@lenPfad - @lenExt) - 1) <span class="kwrd">SET</span> @Command = @Command + <span class="str">'(Name
= '</span> + @Q + @LogicName + @Q + <span class="str">', Filename = '</span> + @Q <span class="kwrd">SET</span> @Command
= @Command + @Pfad + @SnapshotName + <span class="str">'_'</span> + @DBname + <span class="str">'.'</span> + <span class="str">'ssh'</span> +
@Q + <span class="str">'),'</span> + @NewLine <span class="kwrd">END</span><span class="kwrd">FETCH</span><span class="kwrd">NEXT</span><span class="kwrd">FROM</span> c <span class="kwrd">INTO</span> @fname,@LogicName <span class="kwrd">END</span><span class="kwrd">CLOSE</span> c <span class="kwrd">DEALLOCATE</span> c <span class="kwrd">SET</span> @Command
= <span class="kwrd">LEFT</span>(@Command,LEN(@Command)-3) + @NewLine + <span class="str">'AS
SNAPSHOT OF '</span> + @masterdb <span class="kwrd">IF</span> @<span class="kwrd">Execute</span> =
1 <span class="kwrd">BEGIN</span><span class="kwrd">EXEC</span> (@Command) <span class="kwrd">END</span><span class="kwrd">ELSE</span><span class="kwrd">BEGIN</span><span class="kwrd">SELECT</span> @Command <span class="kwrd">AS</span> Command <font color="#0000ff">END</font></pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=0bde9a5a-4f77-4a6d-9310-59a194c1db7c" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>little SQL-helpers: Create database snapshots via stored procedure</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,0bde9a5a-4f77-4a6d-9310-59a194c1db7c.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,0bde9a5a-4f77-4a6d-9310-59a194c1db7c.aspx</link>
      <pubDate>Mon, 24 Sep 2007 16:14:49 GMT</pubDate>
      <description>&lt;p&gt;
Do you want to create database snapshots? And do you want to do it programmatically?
Then you could use this stored procedure...
&lt;/p&gt;
&lt;p&gt;
Enjoy!
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;PROC&lt;/span&gt; [dbo].[spr_CreateSnapshot]
(@Masterdb &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255), @SnapshotName &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255),
@&lt;span class="kwrd"&gt;Execute&lt;/span&gt; &lt;span class="kwrd"&gt;BIT&lt;/span&gt; = 1) &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; NOCOUNT &lt;span class="kwrd"&gt;ON&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @NewLine &lt;span class="kwrd"&gt;CHAR&lt;/span&gt;(2) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @Q &lt;span class="kwrd"&gt;CHAR&lt;/span&gt;(1) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @fname &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @extention &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @Pfad &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @DBname &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @LogicName &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @Command &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(&lt;span class="kwrd"&gt;MAX&lt;/span&gt;) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @indexExt &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @indexPfad &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @lenFname &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @lenPfad &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @lenDB &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @lenExt &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; #Info
(physical_name &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255) &lt;span class="kwrd"&gt;not&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;,
logicname &lt;span class="kwrd"&gt;VARCHAR&lt;/span&gt;(255) &lt;span class="kwrd"&gt;not&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @newLine
= &lt;span class="kwrd"&gt;CHAR&lt;/span&gt;(13) + &lt;span class="kwrd"&gt;CHAR&lt;/span&gt;(10) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @Q
= &lt;span class="kwrd"&gt;CHAR&lt;/span&gt;(39) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @command = &lt;span class="str"&gt;'INSERT
INTO #info (physical_name, logicname) SELECT s.physical_name,s.[name] AS LogicName
FROM '&lt;/span&gt; + Quotename(@masterdb) + &lt;span class="str"&gt;'.sys.filegroups as g INNER
JOIN sys.master_files AS s ON s.type = 0 AND s.database_id = db_id('&lt;/span&gt; + @Q +
@Masterdb + @Q + &lt;span class="str"&gt;') AND s.drop_lsn is null AND s.data_space_id =
g.data_space_id ORDER BY g.data_space_id'&lt;/span&gt; &lt;span class="kwrd"&gt;EXECUTE&lt;/span&gt; (@Command) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @Command
= &lt;span class="str"&gt;'CREATE DATABASE '&lt;/span&gt; + @SnapshotName + @NewLine &lt;span class="kwrd"&gt;SET&lt;/span&gt; @Command
= @Command + &lt;span class="str"&gt;'ON'&lt;/span&gt; + @NewLine &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; c &lt;span class="kwrd"&gt;CURSOR&lt;/span&gt; READ_ONLY &lt;span class="kwrd"&gt;FOR&lt;/span&gt; &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; physical_name,
logicname &lt;span class="kwrd"&gt;FROM&lt;/span&gt; #info &lt;span class="kwrd"&gt;OPEN&lt;/span&gt; c &lt;span class="kwrd"&gt;FETCH&lt;/span&gt; &lt;span class="kwrd"&gt;NEXT&lt;/span&gt; &lt;span class="kwrd"&gt;FROM&lt;/span&gt; c &lt;span class="kwrd"&gt;INTO&lt;/span&gt; @fname,@LogicName &lt;span class="kwrd"&gt;WHILE&lt;/span&gt; (@@fetch_status
&amp;lt;&amp;gt; -1) &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;IF&lt;/span&gt; (@@fetch_status
&amp;lt;&amp;gt; -2) &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;SET&lt;/span&gt; @fname
= REVERSE(@fname) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @lenFname = LEN(@fname) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @indexExt
= CHARINDEX(&lt;span class="str"&gt;'.'&lt;/span&gt;,@fname) -1 &lt;span class="kwrd"&gt;SET&lt;/span&gt; @indexPfad
= CHARINDEX(&lt;span class="str"&gt;'\'&lt;/span&gt;,@fname) - 1 &lt;span class="kwrd"&gt;SET&lt;/span&gt; @extention
= REVERSE(&lt;span class="kwrd"&gt;SUBSTRING&lt;/span&gt; (@fname, 1, @indexExt)) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @lenExt
= LEN(@extention) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @Pfad = &lt;span class="kwrd"&gt;LEFT&lt;/span&gt; (REVERSE(@fname),
@lenFname - @indexPfad) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @lenPfad = LEN(@Pfad) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @DBname
= &lt;span class="kwrd"&gt;SUBSTRING&lt;/span&gt;(REVERSE(@fname), @lenPfad + 1, (@lenFname -
@lenPfad - @lenExt) - 1) &lt;span class="kwrd"&gt;SET&lt;/span&gt; @Command = @Command + &lt;span class="str"&gt;'(Name
= '&lt;/span&gt; + @Q + @LogicName + @Q + &lt;span class="str"&gt;', Filename = '&lt;/span&gt; + @Q &lt;span class="kwrd"&gt;SET&lt;/span&gt; @Command
= @Command + @Pfad + @SnapshotName + &lt;span class="str"&gt;'_'&lt;/span&gt; + @DBname + &lt;span class="str"&gt;'.'&lt;/span&gt; + &lt;span class="str"&gt;'ssh'&lt;/span&gt; +
@Q + &lt;span class="str"&gt;'),'&lt;/span&gt; + @NewLine &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;FETCH&lt;/span&gt; &lt;span class="kwrd"&gt;NEXT&lt;/span&gt; &lt;span class="kwrd"&gt;FROM&lt;/span&gt; c &lt;span class="kwrd"&gt;INTO&lt;/span&gt; @fname,@LogicName &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;CLOSE&lt;/span&gt; c &lt;span class="kwrd"&gt;DEALLOCATE&lt;/span&gt; c &lt;span class="kwrd"&gt;SET&lt;/span&gt; @Command
= &lt;span class="kwrd"&gt;LEFT&lt;/span&gt;(@Command,LEN(@Command)-3) + @NewLine + &lt;span class="str"&gt;'AS
SNAPSHOT OF '&lt;/span&gt; + @masterdb &lt;span class="kwrd"&gt;IF&lt;/span&gt; @&lt;span class="kwrd"&gt;Execute&lt;/span&gt; =
1 &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;EXEC&lt;/span&gt; (@Command) &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;ELSE&lt;/span&gt; &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; @Command &lt;span class="kwrd"&gt;AS&lt;/span&gt; Command &lt;font color="#0000ff"&gt;END&lt;/font&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=0bde9a5a-4f77-4a6d-9310-59a194c1db7c" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,0bde9a5a-4f77-4a6d-9310-59a194c1db7c.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=1774e9d4-2a23-4240-bfae-1c22d40bc270</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,1774e9d4-2a23-4240-bfae-1c22d40bc270.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,1774e9d4-2a23-4240-bfae-1c22d40bc270.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1774e9d4-2a23-4240-bfae-1c22d40bc270</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
You are interested in getting some informations about your SQL Server, for example
to be able to do an auditing on your SQL Server via SSIS, this code will help:
</p>
        <pre class="csharpcode">
          <span class="kwrd">SELECT</span> SERVERPROPERTY (<span class="str">'MachineName'</span>) <span class="kwrd">as</span> MachineName,
SERVERPROPERTY (<span class="str">'InstanceName'</span>) <span class="kwrd">as</span> InstanceName,
SERVERPROPERTY (<span class="str">'ProductVersion'</span>) <span class="kwrd">as</span> ProductVersion,
SERVERPROPERTY (<span class="str">'ProductLevel'</span>) <span class="kwrd">As</span> ProductLevel,
SERVERPROPERTY (<span class="str">'Edition'</span>) <span class="kwrd">as</span> Edition,
SERVERPROPERTY (<span class="str">'LicenseType'</span>) <span class="kwrd">as</span> LicenseType,
SERVERPROPERTY (<span class="str">'NumLicenses'</span>) <span class="kwrd">as</span> NumLicenses,
SERVERPROPERTY (<span class="str">'IsClustered'</span>) <span class="kwrd">as</span> IsClustered,
SERVERPROPERTY (<span class="str">'IsIntegratedSecurityOnly'</span>) <span class="kwrd">as</span> IsIntegratedSecurityOnly</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=1774e9d4-2a23-4240-bfae-1c22d40bc270" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>little SQL-helpers: Get some infos about your SQL Server</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,1774e9d4-2a23-4240-bfae-1c22d40bc270.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,1774e9d4-2a23-4240-bfae-1c22d40bc270.aspx</link>
      <pubDate>Mon, 24 Sep 2007 15:57:03 GMT</pubDate>
      <description>&lt;p&gt;
You are interested in getting some informations about your SQL Server, for example
to be able to do an auditing on your SQL Server via SSIS, this code will help:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; SERVERPROPERTY (&lt;span class="str"&gt;'MachineName'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; MachineName,
SERVERPROPERTY (&lt;span class="str"&gt;'InstanceName'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; InstanceName,
SERVERPROPERTY (&lt;span class="str"&gt;'ProductVersion'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; ProductVersion,
SERVERPROPERTY (&lt;span class="str"&gt;'ProductLevel'&lt;/span&gt;) &lt;span class="kwrd"&gt;As&lt;/span&gt; ProductLevel,
SERVERPROPERTY (&lt;span class="str"&gt;'Edition'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; Edition,
SERVERPROPERTY (&lt;span class="str"&gt;'LicenseType'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; LicenseType,
SERVERPROPERTY (&lt;span class="str"&gt;'NumLicenses'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; NumLicenses,
SERVERPROPERTY (&lt;span class="str"&gt;'IsClustered'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; IsClustered,
SERVERPROPERTY (&lt;span class="str"&gt;'IsIntegratedSecurityOnly'&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; IsIntegratedSecurityOnly&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=1774e9d4-2a23-4240-bfae-1c22d40bc270" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,1774e9d4-2a23-4240-bfae-1c22d40bc270.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=bc048c6b-9338-45ec-82bb-da688eb69c53</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,bc048c6b-9338-45ec-82bb-da688eb69c53.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,bc048c6b-9338-45ec-82bb-da688eb69c53.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=bc048c6b-9338-45ec-82bb-da688eb69c53</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>
            <font color="#003399">
            </font>
          </strong>
        </p>
        <p>
I do not know the original author of this stored procedure...<br />
If you are the one - please send me an email and I will publish the right credits!
</p>
        <p>
After changing the structure of a table or delete one you will need to check and refresh
your views also. This code will help...
</p>
        <pre class="csharpcode">
          <span class="kwrd">DECLARE</span> @Table_Name <span class="kwrd">varchar</span>(100) <span class="kwrd">DECLARE</span> Refresh_Views <span class="kwrd">CURSOR</span><span class="kwrd">FOR</span><span class="kwrd">SELECT</span> Table_Name <span class="kwrd">FROM</span> INFORMATION_SCHEMA.TABLES <span class="kwrd">WHERE</span> TABLE_TYPE
= <span class="str">'VIEW'</span><span class="kwrd">AND</span> TABLE_SCHEMA = <span class="str">'dbo'</span><span class="kwrd">OPEN</span> Refresh_Views <span class="kwrd">FETCH</span><span class="kwrd">NEXT</span><span class="kwrd">FROM</span> Refresh_Views <span class="kwrd">INTO</span> @Table_Name <span class="kwrd">WHILE</span><span class="preproc">@@FETCH_STATUS</span> =
0 <span class="kwrd">BEGIN</span><span class="kwrd">EXEC</span> sp_refreshview @Table_Name <span class="kwrd">FETCH</span><span class="kwrd">NEXT</span><span class="kwrd">FROM</span> Refresh_Views <span class="kwrd">INTO</span> @Table_Name <span class="kwrd">END</span><span class="kwrd">CLOSE</span> Refresh_Views <span class="kwrd">DEALLOCATE</span> Refresh_Views</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
          <strong>
            <font color="#003399">
            </font>
          </strong>
        </p>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=bc048c6b-9338-45ec-82bb-da688eb69c53" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>little SQL-helpers: sp_refreshview</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,bc048c6b-9338-45ec-82bb-da688eb69c53.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,bc048c6b-9338-45ec-82bb-da688eb69c53.aspx</link>
      <pubDate>Mon, 24 Sep 2007 15:51:39 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;&lt;font color="#003399"&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I do not know the original author of this stored procedure...&lt;br&gt;
If you are the one - please send me an email and I will publish the right credits!
&lt;/p&gt;
&lt;p&gt;
After changing the structure of a table or delete one you will need to check and refresh
your views also. This code will help...
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @Table_Name &lt;span class="kwrd"&gt;varchar&lt;/span&gt;(100) &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; Refresh_Views &lt;span class="kwrd"&gt;CURSOR&lt;/span&gt; &lt;span class="kwrd"&gt;FOR&lt;/span&gt; &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; Table_Name &lt;span class="kwrd"&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.TABLES &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; TABLE_TYPE
= &lt;span class="str"&gt;'VIEW'&lt;/span&gt; &lt;span class="kwrd"&gt;AND&lt;/span&gt; TABLE_SCHEMA = &lt;span class="str"&gt;'dbo'&lt;/span&gt; &lt;span class="kwrd"&gt;OPEN&lt;/span&gt; Refresh_Views &lt;span class="kwrd"&gt;FETCH&lt;/span&gt; &lt;span class="kwrd"&gt;NEXT&lt;/span&gt; &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Refresh_Views &lt;span class="kwrd"&gt;INTO&lt;/span&gt; @Table_Name &lt;span class="kwrd"&gt;WHILE&lt;/span&gt; &lt;span class="preproc"&gt;@@FETCH_STATUS&lt;/span&gt; =
0 &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt; &lt;span class="kwrd"&gt;EXEC&lt;/span&gt; sp_refreshview @Table_Name &lt;span class="kwrd"&gt;FETCH&lt;/span&gt; &lt;span class="kwrd"&gt;NEXT&lt;/span&gt; &lt;span class="kwrd"&gt;FROM&lt;/span&gt; Refresh_Views &lt;span class="kwrd"&gt;INTO&lt;/span&gt; @Table_Name &lt;span class="kwrd"&gt;END&lt;/span&gt; &lt;span class="kwrd"&gt;CLOSE&lt;/span&gt; Refresh_Views &lt;span class="kwrd"&gt;DEALLOCATE&lt;/span&gt; Refresh_Views&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font color="#003399"&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=bc048c6b-9338-45ec-82bb-da688eb69c53" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,bc048c6b-9338-45ec-82bb-da688eb69c53.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=ce3ab959-2fe4-40bf-beee-1f73f80d0ebd</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,ce3ab959-2fe4-40bf-beee-1f73f80d0ebd.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,ce3ab959-2fe4-40bf-beee-1f73f80d0ebd.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=ce3ab959-2fe4-40bf-beee-1f73f80d0ebd</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="Extracting Olap Data from SSAS using SSIS" href="http://geekswithblogs.net/darrengosbell/archive/2006/04/26/76418.aspx" target="_blank">Darren
Gosbell</a> has posted a very interesting article about querying SSAS and use the
result in the relational part of SQL Server.
</p>
        <p>
I have used it in a project to retransfer data which was calculated due to a parent
child dimension containing items for a financial analysis.<br />
Calculating this via the relational data would have been a mess, because of having
to rebuild the whole calculation from the bottom to the top of the hierarchy.
</p>
        <p>
All you have to do is to define a linked server in the first step:
</p>
        <pre class="csharpcode">
          <span class="kwrd">USE</span> master <span class="kwrd">GO</span> /* <span class="kwrd">Add</span><span class="kwrd">new</span> linked
server */ <span class="kwrd">EXEC</span> sp_addlinkedserver @server=<span class="str">'LINKED_OLAP'</span>, <span class="rem">--
local SQL name given to the linked server </span> @srvproduct=<span class="str">''</span>, <span class="rem">--
not used </span> @provider=<span class="str">'MSOLAP.3'</span>, <span class="rem">--
OLE DB provider (the .2 means the SQL2K version) </span> @datasrc=<span class="str">'localhost'</span>, <span class="rem">--
analysis server name (machine name) </span> @<span class="kwrd">catalog</span>=<span class="str">'Adventure
Works DW'</span><span class="rem">-- default catalog/database</span></pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
After successfully defining the linked server you will be able to query any SSAS cube
based on your security like this way:
</p>
        <pre class="csharpcode">
          <span class="kwrd">SELECT</span> * <span class="kwrd">FROM</span><span class="kwrd">OpenQuery</span>(linked_olap,<span class="str">'SELECT
--measures.members {Measures.[Internet Sales Amount]} ON COLUMNS, [Date].[Month].members
ON ROWS FROM [Adventure Works]'</span>) </pre>
        <p>
While writing this blog entry I tested it on my notebook also - and was very astonished
that querying the cube does not work, while testing the linked server worked
well.<br />
I am getting an error message like:<br />
"Msg 7399, Level 16, State 1, Line 1<br />
The OLE DB provider "MSOLAP.3" for linked server "linked_olap" reported an error.
The provider did not give any information about the error.<br />
Msg 7330, Level 16, State 2, Line 1<br />
Cannot fetch a row from OLE DB provider "MSOLAP.3" for linked server "linked_olap"."
</p>
        <p>
Maybe it depends on Windows Vista, even with the security set in the right way and
also running SSMS as an administrator...
</p>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=ce3ab959-2fe4-40bf-beee-1f73f80d0ebd" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>little SQL-helpers: Extracting Olap Data from SSAS using SSIS - Darren Gosbell</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,ce3ab959-2fe4-40bf-beee-1f73f80d0ebd.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,ce3ab959-2fe4-40bf-beee-1f73f80d0ebd.aspx</link>
      <pubDate>Tue, 01 May 2007 22:05:16 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="Extracting Olap Data from SSAS using SSIS" href="http://geekswithblogs.net/darrengosbell/archive/2006/04/26/76418.aspx" target="_blank"&gt;Darren
Gosbell&lt;/a&gt; has posted a very interesting article about querying SSAS and use the
result&amp;nbsp;in the relational part of SQL Server.
&lt;/p&gt;
&lt;p&gt;
I have used it in a project to retransfer data which was calculated due to a parent
child dimension containing items for a financial analysis.&lt;br&gt;
Calculating this via the relational data would have been a mess, because of having
to rebuild the whole calculation from the bottom to the top of the hierarchy.
&lt;/p&gt;
&lt;p&gt;
All you have to do is to define a linked server in the first step:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;USE&lt;/span&gt; master &lt;span class="kwrd"&gt;GO&lt;/span&gt; /* &lt;span class="kwrd"&gt;Add&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; linked
server */ &lt;span class="kwrd"&gt;EXEC&lt;/span&gt; sp_addlinkedserver @server=&lt;span class="str"&gt;'LINKED_OLAP'&lt;/span&gt;, &lt;span class="rem"&gt;--
local SQL name given to the linked server &lt;/span&gt; @srvproduct=&lt;span class="str"&gt;''&lt;/span&gt;, &lt;span class="rem"&gt;--
not used &lt;/span&gt; @provider=&lt;span class="str"&gt;'MSOLAP.3'&lt;/span&gt;, &lt;span class="rem"&gt;--
OLE DB provider (the .2 means the SQL2K version) &lt;/span&gt; @datasrc=&lt;span class="str"&gt;'localhost'&lt;/span&gt;, &lt;span class="rem"&gt;--
analysis server name (machine name) &lt;/span&gt; @&lt;span class="kwrd"&gt;catalog&lt;/span&gt;=&lt;span class="str"&gt;'Adventure
Works DW'&lt;/span&gt; &lt;span class="rem"&gt;-- default catalog/database&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
After successfully defining the linked server you will be able to query any SSAS cube
based on your security like this way:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;FROM&lt;/span&gt; &lt;span class="kwrd"&gt;OpenQuery&lt;/span&gt;(linked_olap,&lt;span class="str"&gt;'SELECT
--measures.members {Measures.[Internet Sales Amount]} ON COLUMNS, [Date].[Month].members
ON ROWS FROM [Adventure Works]'&lt;/span&gt;) &lt;/pre&gt;
&lt;p&gt;
While writing this blog entry I tested it on my notebook also - and was very astonished
that&amp;nbsp;querying the cube&amp;nbsp;does not work, while testing the linked server worked
well.&lt;br&gt;
I am getting an error message like:&lt;br&gt;
"Msg 7399, Level 16, State 1, Line 1&lt;br&gt;
The OLE DB provider "MSOLAP.3" for linked server "linked_olap" reported an error.
The provider did not give any information about the error.&lt;br&gt;
Msg 7330, Level 16, State 2, Line 1&lt;br&gt;
Cannot fetch a row from OLE DB provider "MSOLAP.3" for linked server "linked_olap"."
&lt;/p&gt;
&lt;p&gt;
Maybe it depends on Windows Vista, even with the security set in the right way and
also running SSMS as an administrator...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=ce3ab959-2fe4-40bf-beee-1f73f80d0ebd" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,ce3ab959-2fe4-40bf-beee-1f73f80d0ebd.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/AS - SSAS;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=079d6d52-c549-41e2-9431-8e4a281414d8</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,079d6d52-c549-41e2-9431-8e4a281414d8.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,079d6d52-c549-41e2-9431-8e4a281414d8.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=079d6d52-c549-41e2-9431-8e4a281414d8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a title="Narayana Vyas Kondreddi" href="http://vyaskn.tripod.com/" target="_blank">Narayana
Vyas Kondreddi</a> has published some nice little sql helpers to search and replace
data in various tables - therefor the following content is intellectual property of <a title="Narayana Vyas Kondreddi" href="http://vyaskn.tripod.com/" target="_blank">Narayana
Vyas Kondreddi</a>.
</p>
        <p>
Maybe you will have to adjust the sql commands to search only special tables via a
prefix for example or to just search via a special column...
</p>
        <p>
          <hr width="75%" color="#c0c0c0" size="1" />
        </p>
        <p>
        </p>
        <p>
The first one, <a title="SearchAllTables" href="http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm" target="_blank">SearchAllTables</a>,
can search all the columns of all the tables in a given database for a specific keyword:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROC</span> SearchAllTables<br />
(<br />
@SearchStr <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(100)<br />
)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Purpose: To search all columns of all tables for a given search string</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Written by: Narayana Vyas Kondreddi</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Site: http://vyaskn.tripod.com</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Tested on: SQL Server 7.0 and SQL Server 2000</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Date modified: 28th July 2002 22:50 GMT</span><br /><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TABLE</span> #Results
(ColumnName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(370),
ColumnValue <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(3630))<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOCOUNT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @TableName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(256),
@ColumnName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(128),
@SearchStr2 <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(110)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @TableName
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @SearchStr2
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'%'</span> +
@SearchStr + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'%'</span>,<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''''</span>)<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> @TableName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @ColumnName
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @TableName
= 
<br />
(<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">MIN</span>(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_SCHEMA)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_NAME))<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> INFORMATION_SCHEMA.TABLES<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> TABLE_TYPE
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'BASE
TABLE'</span><br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_SCHEMA)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_NAME)
&gt; @TableName<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECTPROPERTY</span>(<br /><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECT_ID</span>(<br /><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_SCHEMA)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_NAME)<br />
), <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'IsMSShipped'</span><br />
) = 0<br />
)<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> (@TableName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span>) <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> (@ColumnName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span>)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @ColumnName
=<br />
(<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">MIN</span>(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(COLUMN_NAME))<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> INFORMATION_SCHEMA.COLUMNS<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> TABLE_SCHEMA
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PARSENAME</span>(@TableName,
2)<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> TABLE_NAME
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PARSENAME</span>(@TableName,
1)<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> DATA_TYPE <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IN</span> (<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'char'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'varchar'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'nchar'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'nvarchar'</span>)<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(COLUMN_NAME)
&gt; @ColumnName<br />
)<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IF</span> @ColumnName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INSERT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INTO</span> #Results<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span><br />
(<br /><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'SELECT
'''</span> + @TableName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.'</span> +
@ColumnName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''',
LEFT('</span> + @ColumnName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">',
3630) 
<br />
FROM '</span> + @TableName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
(NOLOCK) '</span> +<br /><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
WHERE '</span> + @ColumnName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
LIKE '</span> + @SearchStr2<br />
)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> ColumnName,
ColumnValue <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #Results<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span></span>
        </p>
        <hr width="75%" color="#c0c0c0" size="1" />
        <p>
The second one, <a title="SearchAndReplace" href="http://vyaskn.tripod.com/sql_server_search_and_replace.htm" target="_blank">SearchAndReplace</a>,
does not only perform the search but also will do a replace:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROC</span> SearchAndReplace<br />
(<br />
@SearchStr <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(100),<br />
@ReplaceStr <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(100)<br />
)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Purpose: To search all columns of all tables for a given search string and replace
it with another string</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Written by: Narayana Vyas Kondreddi</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Site: http://vyaskn.tripod.com</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Tested on: SQL Server 7.0 and SQL Server 2000</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--
Date modified: 2nd November 2002 13:50 GMT</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOCOUNT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @TableName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(256),
@ColumnName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(128),
@SearchStr2 <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(110),
@SQL <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">nvarchar</span>(4000),
@RCTR <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">int</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @TableName
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @SearchStr2
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'%'</span> +
@SearchStr + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'%'</span>,<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''''</span>)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @RCTR
= 0<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> @TableName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @ColumnName
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @TableName
= 
<br />
(<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">MIN</span>(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_SCHEMA)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_NAME))<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> INFORMATION_SCHEMA.TABLES<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> TABLE_TYPE
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'BASE
TABLE'</span><br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_SCHEMA)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_NAME)
&gt; @TableName<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECTPROPERTY</span>(<br /><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECT_ID</span>(<br /><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_SCHEMA)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(TABLE_NAME)<br />
), <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'IsMSShipped'</span><br />
) = 0<br />
)<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> (@TableName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span>) <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> (@ColumnName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span>)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @ColumnName
=<br />
(<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">MIN</span>(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(COLUMN_NAME))<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> INFORMATION_SCHEMA.COLUMNS<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> TABLE_SCHEMA
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PARSENAME</span>(@TableName,
2)<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> TABLE_NAME
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PARSENAME</span>(@TableName,
1)<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> DATA_TYPE <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IN</span> (<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'char'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'varchar'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'nchar'</span>, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'nvarchar'</span>)<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(COLUMN_NAME)
&gt; @ColumnName<br />
)<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IF</span> @ColumnName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @SQL= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'UPDATE
'</span> + @TableName + 
<br /><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
SET '</span> + @ColumnName 
<br />
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
= REPLACE('</span> + @ColumnName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">',
'</span><br />
+ <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(@SearchStr, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''''</span>)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">',
'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">QUOTENAME</span>(@ReplaceStr, <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">''''</span>)
+ 
<br /><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">')
WHERE '</span> + @ColumnName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
LIKE '</span> + @SearchStr2<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span> (@SQL)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @RCTR
= @RCTR + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">@@ROWCOUNT</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Replaced
'</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CAST</span>(@RCTR <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
occurence(s)'</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Outcome'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /></span>
        </p>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=079d6d52-c549-41e2-9431-8e4a281414d8" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>little SQL-helpers: search and replace data from Narayana Vyas Kondreddi</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,079d6d52-c549-41e2-9431-8e4a281414d8.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,079d6d52-c549-41e2-9431-8e4a281414d8.aspx</link>
      <pubDate>Tue, 01 May 2007 19:37:56 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a title="Narayana Vyas Kondreddi" href="http://vyaskn.tripod.com/" target=_blank&gt;Narayana
Vyas Kondreddi&lt;/a&gt; has published some nice little sql helpers to search and&amp;nbsp;replace
data in various tables - therefor the following content is intellectual property of &lt;a title="Narayana Vyas Kondreddi" href="http://vyaskn.tripod.com/" target=_blank&gt;Narayana
Vyas Kondreddi&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Maybe you will have to adjust the sql commands to search only special tables via a
prefix for example&amp;nbsp;or to just search via a special column...
&lt;/p&gt;
&lt;p&gt;
&lt;hr width="75%" color=#c0c0c0 size=1&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
The first one, &lt;a title=SearchAllTables href="http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm" target=_blank&gt;SearchAllTables&lt;/a&gt;,
can search all the columns of all the tables in a given database for a specific keyword:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROC&lt;/span&gt; SearchAllTables&lt;br&gt;
(&lt;br&gt;
@SearchStr &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(100)&lt;br&gt;
)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Purpose: To search all columns of all tables for a given search string&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Written by: Narayana Vyas Kondreddi&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Site: http://vyaskn.tripod.com&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Tested on: SQL Server 7.0 and SQL Server 2000&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Date modified: 28th July 2002 22:50 GMT&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TABLE&lt;/span&gt; #Results
(ColumnName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(370),
ColumnValue &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(3630))&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOCOUNT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @TableName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(256),
@ColumnName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(128),
@SearchStr2 &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(110)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @TableName
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @SearchStr2
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'%'&lt;/span&gt; +
@SearchStr + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'%'&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''''&lt;/span&gt;)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; @TableName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @ColumnName
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @TableName
= 
&lt;br&gt;
(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;MIN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_SCHEMA)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_NAME))&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.TABLES&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; TABLE_TYPE
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'BASE
TABLE'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_SCHEMA)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_NAME)
&amp;gt; @TableName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECTPROPERTY&lt;/span&gt;(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECT_ID&lt;/span&gt;(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_SCHEMA)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_NAME)&lt;br&gt;
), &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'IsMSShipped'&lt;/span&gt;
&lt;br&gt;
) = 0&lt;br&gt;
)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; (@TableName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; (@ColumnName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @ColumnName
=&lt;br&gt;
(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;MIN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(COLUMN_NAME))&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.COLUMNS&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; TABLE_SCHEMA
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PARSENAME&lt;/span&gt;(@TableName,
2)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; TABLE_NAME
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PARSENAME&lt;/span&gt;(@TableName,
1)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; DATA_TYPE &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IN&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'char'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'varchar'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'nchar'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'nvarchar'&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(COLUMN_NAME)
&amp;gt; @ColumnName&lt;br&gt;
)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IF&lt;/span&gt; @ColumnName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INSERT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INTO&lt;/span&gt; #Results&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt;
&lt;br&gt;
(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'SELECT
'''&lt;/span&gt; + @TableName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.'&lt;/span&gt; +
@ColumnName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''',
LEFT('&lt;/span&gt; + @ColumnName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;',
3630) 
&lt;br&gt;
FROM '&lt;/span&gt; + @TableName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
(NOLOCK) '&lt;/span&gt; +&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
WHERE '&lt;/span&gt; + @ColumnName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
LIKE '&lt;/span&gt; + @SearchStr2&lt;br&gt;
)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt; 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; ColumnName,
ColumnValue &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #Results&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;hr width="75%" color=#c0c0c0 size=1&gt;
&lt;p&gt;
The&amp;nbsp;second one, &lt;a title=SearchAndReplace href="http://vyaskn.tripod.com/sql_server_search_and_replace.htm" target=_blank&gt;SearchAndReplace&lt;/a&gt;,
does not only perform the search but also will do a replace:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROC&lt;/span&gt; SearchAndReplace&lt;br&gt;
(&lt;br&gt;
@SearchStr &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(100),&lt;br&gt;
@ReplaceStr &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(100)&lt;br&gt;
)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Purpose: To search all columns of all tables for a given search string and replace
it with another string&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Written by: Narayana Vyas Kondreddi&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Site: http://vyaskn.tripod.com&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Tested on: SQL Server 7.0 and SQL Server 2000&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--
Date modified: 2nd November 2002 13:50 GMT&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOCOUNT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @TableName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(256),
@ColumnName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(128),
@SearchStr2 &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(110),
@SQL &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;nvarchar&lt;/span&gt;(4000),
@RCTR &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @TableName
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @SearchStr2
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'%'&lt;/span&gt; +
@SearchStr + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'%'&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''''&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @RCTR
= 0&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; @TableName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @ColumnName
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @TableName
= 
&lt;br&gt;
(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;MIN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_SCHEMA)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_NAME))&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.TABLES&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; TABLE_TYPE
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'BASE
TABLE'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_SCHEMA)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_NAME)
&amp;gt; @TableName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECTPROPERTY&lt;/span&gt;(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECT_ID&lt;/span&gt;(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_SCHEMA)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(TABLE_NAME)&lt;br&gt;
), &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'IsMSShipped'&lt;/span&gt;
&lt;br&gt;
) = 0&lt;br&gt;
)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; (@TableName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; (@ColumnName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @ColumnName
=&lt;br&gt;
(&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;MIN&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(COLUMN_NAME))&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.COLUMNS&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; TABLE_SCHEMA
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PARSENAME&lt;/span&gt;(@TableName,
2)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; TABLE_NAME
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PARSENAME&lt;/span&gt;(@TableName,
1)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; DATA_TYPE &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IN&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'char'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'varchar'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'nchar'&lt;/span&gt;, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'nvarchar'&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(COLUMN_NAME)
&amp;gt; @ColumnName&lt;br&gt;
)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IF&lt;/span&gt; @ColumnName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @SQL= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'UPDATE
'&lt;/span&gt; + @TableName + 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
SET '&lt;/span&gt; + @ColumnName 
&lt;br&gt;
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
= REPLACE('&lt;/span&gt; + @ColumnName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;',
'&lt;/span&gt; 
&lt;br&gt;
+ &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(@SearchStr, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''''&lt;/span&gt;)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;',
'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;QUOTENAME&lt;/span&gt;(@ReplaceStr, &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;''''&lt;/span&gt;)
+ 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;')
WHERE '&lt;/span&gt; + @ColumnName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
LIKE '&lt;/span&gt; + @SearchStr2&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; (@SQL)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @RCTR
= @RCTR + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;@@ROWCOUNT&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt; 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Replaced
'&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CAST&lt;/span&gt;(@RCTR &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
occurence(s)'&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Outcome'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;style type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=079d6d52-c549-41e2-9431-8e4a281414d8" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,079d6d52-c549-41e2-9431-8e4a281414d8.aspx</comments>
      <category>Development;Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=b823007e-7e41-42fb-8e18-7506c52724d6</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,b823007e-7e41-42fb-8e18-7506c52724d6.aspx</pingback:target>
      <dc:creator>Klaus Hoeltgen</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,b823007e-7e41-42fb-8e18-7506c52724d6.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=b823007e-7e41-42fb-8e18-7506c52724d6</wfw:commentRss>
      <title>little SQL-helpers: all base tables of a view </title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,b823007e-7e41-42fb-8e18-7506c52724d6.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,b823007e-7e41-42fb-8e18-7506c52724d6.aspx</link>
      <pubDate>Tue, 24 Apr 2007 12:20:16 GMT</pubDate>
      <description>To get all base tables of a view you can use the following CTE-Statement...&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=b823007e-7e41-42fb-8e18-7506c52724d6"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,b823007e-7e41-42fb-8e18-7506c52724d6.aspx</comments>
      <category>Development;Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=b31898e3-8528-4ad5-a0d5-b9c943758364</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,b31898e3-8528-4ad5-a0d5-b9c943758364.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,b31898e3-8528-4ad5-a0d5-b9c943758364.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=b31898e3-8528-4ad5-a0d5-b9c943758364</wfw:commentRss>
      <title>little SQL-helpers: fillup string</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,b31898e3-8528-4ad5-a0d5-b9c943758364.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,b31898e3-8528-4ad5-a0d5-b9c943758364.aspx</link>
      <pubDate>Wed, 31 Jan 2007 09:51:35 GMT</pubDate>
      <description>If you need to fill up a string to a defined total count you will be glad if you have a function like this:&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=b31898e3-8528-4ad5-a0d5-b9c943758364"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,b31898e3-8528-4ad5-a0d5-b9c943758364.aspx</comments>
      <category>Development;Development/T-SQL</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=2e099b13-1d06-4eec-8b78-35d3f26f08cb</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,2e099b13-1d06-4eec-8b78-35d3f26f08cb.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,2e099b13-1d06-4eec-8b78-35d3f26f08cb.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=2e099b13-1d06-4eec-8b78-35d3f26f08cb</wfw:commentRss>
      <title>little SQL-helpers: Last day of month</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,2e099b13-1d06-4eec-8b78-35d3f26f08cb.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,2e099b13-1d06-4eec-8b78-35d3f26f08cb.aspx</link>
      <pubDate>Wed, 31 Jan 2007 09:46:00 GMT</pubDate>
      <description>Do you need the last day of a month in a SQL Statement?&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=2e099b13-1d06-4eec-8b78-35d3f26f08cb"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,2e099b13-1d06-4eec-8b78-35d3f26f08cb.aspx</comments>
      <category>Development;Development/T-SQL</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=a1179a96-7394-457b-bff5-c7efca6bd6fa</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,a1179a96-7394-457b-bff5-c7efca6bd6fa.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,a1179a96-7394-457b-bff5-c7efca6bd6fa.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=a1179a96-7394-457b-bff5-c7efca6bd6fa</wfw:commentRss>
      <title>System Views in SQL Server 2005</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,a1179a96-7394-457b-bff5-c7efca6bd6fa.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,a1179a96-7394-457b-bff5-c7efca6bd6fa.aspx</link>
      <pubDate>Wed, 25 Oct 2006 22:00:30 GMT</pubDate>
      <description>You will find a complete overview for the System Views at http://msdn2.microsoft.com/en-us/library/ms177862.aspx.

The most usefull ones of the Catalog Views probably will be

Object Catalog Views
Security Catalog Views
To query metadata you will have to use the Information Schema Views.

If you need some hints on how to use the SQL Server System Catalog have a look at Querying the SQL Server System Catalog and the Querying the SQL Server System Catalog FAQ for some examples.&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=a1179a96-7394-457b-bff5-c7efca6bd6fa"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,a1179a96-7394-457b-bff5-c7efca6bd6fa.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=853ce370-e07b-43e0-9664-0829cc6041cc</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,853ce370-e07b-43e0-9664-0829cc6041cc.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,853ce370-e07b-43e0-9664-0829cc6041cc.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=853ce370-e07b-43e0-9664-0829cc6041cc</wfw:commentRss>
      <title>Brett Kaiser: How do I track data changes in a database</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,853ce370-e07b-43e0-9664-0829cc6041cc.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,853ce370-e07b-43e0-9664-0829cc6041cc.aspx</link>
      <pubDate>Sun, 27 Aug 2006 14:09:14 GMT</pubDate>
      <description>Brett Kaiser has posted a article called "How do I track data changes in a database" including his real usefull coding about his idea of doing this via T-SQL automatically erver time a DELETE or UPDATE Modification will be done.

The following content is intellectual property of Brett Kaiser, the original posting can be found here:&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=853ce370-e07b-43e0-9664-0829cc6041cc"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,853ce370-e07b-43e0-9664-0829cc6041cc.aspx</comments>
      <category>Development;Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9</wfw:commentRss>
      <title>Common table expression (CTE) in SQL Server 2005</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9.aspx</link>
      <pubDate>Sun, 27 Aug 2006 13:39:40 GMT</pubDate>
      <description>Nigel Rivett has published an interesting detailed article about common table expressions in SQL Server 2005 on simple-talk.com.&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,fd1448c3-2bfc-4d7c-b58b-70f84e71f6a9.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=4f42c907-3e39-4283-a4fb-c3e536ce2ceb</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,4f42c907-3e39-4283-a4fb-c3e536ce2ceb.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,4f42c907-3e39-4283-a4fb-c3e536ce2ceb.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=4f42c907-3e39-4283-a4fb-c3e536ce2ceb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.sql-server-performance.com/randy_dyess.asp" target="_blank">Randy
Dyess</a> has published an article called <a href="http://www.sql-server-performance.com/rd_auditing2.asp" target="_blank">"Auditing
Your SQL Server Environment: Part II (Reviewing Role Memberships)"</a></p>
        <p>
The following content is intellectual property of Randy Dyess, the original posting
can be found <a href="http://www.sql-server-performance.com/rd_auditing2.asp" target="_blank">here</a>:
</p>
        <p>
          <font color="#808080">"Roles should be in foremost in your mind when planning the
security of your SQL Server environments. Auditing inherited SQL Server installations
is a relatively easy thing to accomplish, and all DBAs should audit their environment
and create documentation if they have not already done so. Once you can document the
logins assigned to each of your fixed and user-defined roles, you can start to remove
any duplication of permissions which can reduce the time needed to troubleshoot future
permission errors."</font>
        </p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Use
the master database</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">USE</span> master<br />
go<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IF</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECT_ID</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'dbo.spRoleMembers'</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DROP</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROCEDURE</span> dbo.spRoleMembers<br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROCEDURE</span> dbo.spRoleMembers<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/************************************************************ 
<br />
Creation Date: 04/28/02 Created By: Randy Dyess<br />
Web Site: www.TransactSQL.Com<br />
Email: RandyDyess@TransactSQL.Com<br />
Purpose: Loops through all databases and obtains member<br />
for database roles as well as server role members.<br />
Location: master database<br />
Output Parameters: None<br />
Return Status: None<br />
Called By: None 
<br />
Calls: None<br />
Data Modifications: None<br />
Updates: 
<br />
None 
<br /><br />
************************************************************/</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOCOUNT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Variables</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @lngCounter
INTEGER<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @strDBName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @strSQL <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NVARCHAR</span>(4000)<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Temp
table to hold database and user-define role user names</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TABLE</span> #tRolemember<br />
(<br />
strServerName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DEFAULT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">@@SERVERNAME</span><br />
,strDBName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50) 
<br />
,strRoleName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50)<br />
,strUserName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50)<br />
,strUserID <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(100)<br />
)<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Temp
table to hold database names</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TABLE</span> #tDBNames<br />
(lngID INTEGER <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IDENTITY</span>(1,1)<br />
,strDBName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50)<br />
)<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Create
permanent table</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IF</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECT_ID</span> (<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'dbo.tRolemember'</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TABLE</span> dbo.tRolemember<br />
(<br />
strServerName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50) 
<br />
,strDBName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50) 
<br />
,strRoleName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50)<br />
,strUserName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(50)<br />
,strUserID <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(100)<br />
)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Obtain
members of each server role</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INSERT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INTO</span> #tRolemember
(strRoleName, strUserName, strUserID)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span> dbo.sp_helpsrvrolemember<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Obtain
database names</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INSERT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INTO</span> #tDBNames
(strDBName)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> name <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> master.dbo.<span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">sysdatabases</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">@@ROWCOUNT</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Loop
through databases to obtain members of database roles and user-defined roles</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> @lngCounter
&gt; 0<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Get
database name from temp table</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @strDBName
= (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strDBName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #tDBNames <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> lngID
= @lngCounter)<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Obtain
members of each database and user-defined role</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @strSQL
= <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'INSERT
INTO #tRolemember (strRoleName, strUserName, strUserID)<br />
EXEC '</span> + @strDBName + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'.dbo.sp_helprolemember'</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span><span style="FONT-SIZE: 11px; COLOR: brown; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">sp_executesql</span> @strSQL<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Update
database name in temp table</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">UPDATE</span> #tRolemember<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> strDBName
= @strDBName<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> strDBName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter
= @lngCounter - 1<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Place
data into permanent table</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INSERT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INTO</span> tRolemember<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> trm.* <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #tRolemember
trm<br /><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEFT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">JOIN</span> tRoleMember
prm<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> trm.strUserName
= prm.strUserName<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> trm.strDBName
= prm.strDBName<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> trm.strRoleName
= prm.strRoleName<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> trm.strServerName
= prm.strServerName<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> prm.strServerName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Test
Stored Procedure</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span> dbo.spRoleMembers<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Display
by User'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strUserName,
strDBName, strRoleName, strServerName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tRolemember<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> strUserName
&lt;&gt; <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'dbo'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ORDER</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BY</span> strUserName<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Display
by Role'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strRoleName,
strDBName, strUserName,strServerName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tRolemember<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> strUserName
&lt;&gt; <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'dbo'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ORDER</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BY</span> strRoleName<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Display
by Database'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strDBName,
strRoleName,strUserName, strServerName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> tRolemember<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> strUserName
&lt;&gt; <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'dbo'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ORDER</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BY</span> strDBName</span>
        </p>
        <p>
          <hr width="75%" color="#c0c0c0" size="1" />
        </p>
        <p>
        </p>
        <p>
Randy also has published a script about auditing user's passwords
</p>
        <p>
The following content is intellectual property of Randy Dyess, the original posting
can be found <a href="http://www.database-security.info/Tools/SQLServer/spAuditPasswords.txt" target="_blank">here</a>:
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IF</span>
            <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECT_ID</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'dbo.spAuditPasswords'</span>) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DROP</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROCEDURE</span> dbo.spAuditPasswords<br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROCEDURE</span> dbo.spAuditPasswords<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/**************************************************************************** 
<br />
Creation Date: 03/22/02 Created By: Randy Dyess<br />
Web Site: www.TransactSQL.Com<br />
Email: RandyDyess@TransactSQL.Com<br />
Purpose: Perform a simple audit of user's passwords<br />
Location: master database<br />
Output Parameters: None<br />
Return Status: None<br />
Called By: None 
<br />
Calls: None<br />
Data Modifications: None<br />
Updates: None 
<br />
Date Author Purpose 
<br />
---------- -------------------------- --------------------------------- 
<br />
****************************************************************************/</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOCOUNT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Variables</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @lngCounter
INTEGER<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @lngCounter1
INTEGER<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @lngLogCount
INTEGER<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @strName <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">VARCHAR</span>(256)<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Create
table to hold SQL logins</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TABLE</span> #tLogins<br />
(<br />
numID INTEGER <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IDENTITY</span>(1,1)<br />
,strLogin <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SYSNAME</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br />
,lngPass INTEGER <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br />
)<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Insert
non ntuser into temp table</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INSERT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">INTO</span> #tLogins
(strLogin)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> name <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> master.dbo.<span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">syslogins</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> isntname
= 0<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngLogCount
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">@@ROWCOUNT</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Determine
if password is null and user iis SQL Login</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'The
following logins have blank passwords'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> name <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Login
Name'</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> master.dbo.<span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">syslogins</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> password <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> isntname
= 0<br /><br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Determine
if password and name are the ssame</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter
= @lngLogCount<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> @lngCounter
&lt;&gt; 0<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @strName
= (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strLogin <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #tLogins <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> numID
= @lngCounter)<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">UPDATE</span> #tLogins<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> lngPass
= (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> PWDCOMPARE
(@strName,(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> password <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> master.dbo.<span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">syslogins</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> name
= @strName))) 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> numID
= @lngCounter<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter
= @lngCounter - 1<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'The
following logins have passwords the same as their login name'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strLogin <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Login
Name'</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #tLogins <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> lngPass
= 1<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Reset
column for next password test</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">UPDATE</span> #tLogins<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> lngPass
= 0<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Determine
if password is only one characcter long</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter
= @lngLogCount<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> @lngCounter
&lt;&gt; 0<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter1
= 1<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @strName
= (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strLogin <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #tLogins <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> numID
= @lngCounter)<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHILE</span> @lngCounter1
&lt; 256<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">UPDATE</span> #tLogins<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> lngPass
= (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> PWDCOMPARE
(<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CHAR</span>(@lngCounter1),(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> password <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> master.dbo.<span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">syslogins</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> name
= @strName))) 
<br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> numID
= @lngCounter<br />
        <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AND</span> lngPass
&lt;&gt; 1<br />
        <br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter1
= @lngCounter1 + 1<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SET</span> @lngCounter
= @lngCounter - 1<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'The
following logins have one character passwords'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> strLogin <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Login
Name'</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #tLogins <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> lngPass
= 1<br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Test</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span> dbo.spAuditPasswords</span>
        </p>
        <p>
          <hr width="75%" color="#c0c0c0" size="1" />
        </p>
        <p>
        </p>
        <p>
And last but not least Bradley Morris has published an article about <a href="http://www.sql-server-performance.com/bm_object_permission_scripts.asp">"How
to Script User and Role Object Permissions in SQL Server"</a></p>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=4f42c907-3e39-4283-a4fb-c3e536ce2ceb" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>some SQL Server scripts regarding security </title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,4f42c907-3e39-4283-a4fb-c3e536ce2ceb.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,4f42c907-3e39-4283-a4fb-c3e536ce2ceb.aspx</link>
      <pubDate>Fri, 25 Aug 2006 13:19:02 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.sql-server-performance.com/randy_dyess.asp" target=_blank&gt;Randy
Dyess&lt;/a&gt; has published an article called &lt;a href="http://www.sql-server-performance.com/rd_auditing2.asp" target=_blank&gt;"Auditing
Your SQL Server Environment: Part II (Reviewing Role Memberships)"&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The following content is intellectual property of Randy Dyess, the original posting
can be found &lt;a href="http://www.sql-server-performance.com/rd_auditing2.asp" target=_blank&gt;here&lt;/a&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#808080&gt;"Roles should be in foremost in your mind when planning the security
of your SQL Server environments. Auditing inherited SQL Server installations is a
relatively easy thing to accomplish, and all DBAs should audit their environment and
create documentation if they have not already done so. Once you can document the logins
assigned to each of your fixed and user-defined roles, you can start to remove any
duplication of permissions which can reduce the time needed to troubleshoot future
permission errors."&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Use
the master database&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;USE&lt;/span&gt; master&lt;br&gt;
go&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IF&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECT_ID&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'dbo.spRoleMembers'&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DROP&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROCEDURE&lt;/span&gt; dbo.spRoleMembers&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROCEDURE&lt;/span&gt; dbo.spRoleMembers&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;/************************************************************ 
&lt;br&gt;
Creation Date: 04/28/02 Created By: Randy Dyess&lt;br&gt;
Web Site: www.TransactSQL.Com&lt;br&gt;
Email: RandyDyess@TransactSQL.Com&lt;br&gt;
Purpose: Loops through all databases and obtains member&lt;br&gt;
for database roles as well as server role members.&lt;br&gt;
Location: master database&lt;br&gt;
Output Parameters: None&lt;br&gt;
Return Status: None&lt;br&gt;
Called By: None 
&lt;br&gt;
Calls: None&lt;br&gt;
Data Modifications: None&lt;br&gt;
Updates: 
&lt;br&gt;
None 
&lt;br&gt;
&lt;br&gt;
************************************************************/&lt;/span&gt; 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOCOUNT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Variables&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @lngCounter
INTEGER&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @strDBName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @strSQL &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NVARCHAR&lt;/span&gt;(4000)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Temp
table to hold database and user-define role user names&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TABLE&lt;/span&gt; #tRolemember&lt;br&gt;
(&lt;br&gt;
strServerName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DEFAULT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;@@SERVERNAME&lt;/span&gt;
&lt;br&gt;
,strDBName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50) 
&lt;br&gt;
,strRoleName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50)&lt;br&gt;
,strUserName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50)&lt;br&gt;
,strUserID &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(100)&lt;br&gt;
)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Temp
table to hold database names&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TABLE&lt;/span&gt; #tDBNames&lt;br&gt;
(lngID INTEGER &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IDENTITY&lt;/span&gt;(1,1)&lt;br&gt;
,strDBName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50)&lt;br&gt;
)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Create
permanent table&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IF&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECT_ID&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'dbo.tRolemember'&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TABLE&lt;/span&gt; dbo.tRolemember&lt;br&gt;
(&lt;br&gt;
strServerName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50) 
&lt;br&gt;
,strDBName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50) 
&lt;br&gt;
,strRoleName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50)&lt;br&gt;
,strUserName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(50)&lt;br&gt;
,strUserID &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(100)&lt;br&gt;
)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Obtain
members of each server role&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INSERT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INTO&lt;/span&gt; #tRolemember
(strRoleName, strUserName, strUserID)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; dbo.sp_helpsrvrolemember&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Obtain
database names&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INSERT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INTO&lt;/span&gt; #tDBNames
(strDBName)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; name &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; master.dbo.&lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;sysdatabases&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;@@ROWCOUNT&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Loop
through databases to obtain members of database roles and user-defined roles&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; @lngCounter
&amp;gt; 0&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Get
database name from temp table&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @strDBName
= (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strDBName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #tDBNames &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; lngID
= @lngCounter)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Obtain
members of each database and user-defined role&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @strSQL
= &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'INSERT
INTO #tRolemember (strRoleName, strUserName, strUserID)&lt;br&gt;
EXEC '&lt;/span&gt; + @strDBName + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'.dbo.sp_helprolemember'&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: brown; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;sp_executesql&lt;/span&gt; @strSQL&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Update
database name in temp table&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;UPDATE&lt;/span&gt; #tRolemember&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; strDBName
= @strDBName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; strDBName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter
= @lngCounter - 1&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Place
data into permanent table&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INSERT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INTO&lt;/span&gt; tRolemember&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; trm.* &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #tRolemember
trm&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEFT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;JOIN&lt;/span&gt; tRoleMember
prm&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; trm.strUserName
= prm.strUserName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; trm.strDBName
= prm.strDBName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; trm.strRoleName
= prm.strRoleName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; trm.strServerName
= prm.strServerName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; prm.strServerName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Test
Stored Procedure&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; dbo.spRoleMembers&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Display
by User'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strUserName,
strDBName, strRoleName, strServerName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tRolemember&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; strUserName
&amp;lt;&amp;gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'dbo'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ORDER&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BY&lt;/span&gt; strUserName&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Display
by Role'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strRoleName,
strDBName, strUserName,strServerName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tRolemember&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; strUserName
&amp;lt;&amp;gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'dbo'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ORDER&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BY&lt;/span&gt; strRoleName&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Display
by Database'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strDBName,
strRoleName,strUserName, strServerName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; tRolemember&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; strUserName
&amp;lt;&amp;gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'dbo'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ORDER&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BY&lt;/span&gt; strDBName&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;hr width="75%" color=#c0c0c0 size=1&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Randy also has published a script about auditing user's passwords
&lt;/p&gt;
&lt;p&gt;
The following content is intellectual property of Randy Dyess, the original posting
can be found &lt;a href="http://www.database-security.info/Tools/SQLServer/spAuditPasswords.txt" target=_blank&gt;here&lt;/a&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IF&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECT_ID&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'dbo.spAuditPasswords'&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DROP&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROCEDURE&lt;/span&gt; dbo.spAuditPasswords&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROCEDURE&lt;/span&gt; dbo.spAuditPasswords&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;/**************************************************************************** 
&lt;br&gt;
Creation Date: 03/22/02 Created By: Randy Dyess&lt;br&gt;
Web Site: www.TransactSQL.Com&lt;br&gt;
Email: RandyDyess@TransactSQL.Com&lt;br&gt;
Purpose: Perform a simple audit of user's passwords&lt;br&gt;
Location: master database&lt;br&gt;
Output Parameters: None&lt;br&gt;
Return Status: None&lt;br&gt;
Called By: None 
&lt;br&gt;
Calls: None&lt;br&gt;
Data Modifications: None&lt;br&gt;
Updates: None 
&lt;br&gt;
Date Author Purpose 
&lt;br&gt;
---------- -------------------------- --------------------------------- 
&lt;br&gt;
****************************************************************************/&lt;/span&gt; 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOCOUNT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Variables&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @lngCounter
INTEGER&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @lngCounter1
INTEGER&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @lngLogCount
INTEGER&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @strName &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;VARCHAR&lt;/span&gt;(256)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Create
table to hold SQL logins&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TABLE&lt;/span&gt; #tLogins&lt;br&gt;
(&lt;br&gt;
numID INTEGER &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IDENTITY&lt;/span&gt;(1,1)&lt;br&gt;
,strLogin &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SYSNAME&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
,lngPass INTEGER &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Insert
non ntuser into temp table&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INSERT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;INTO&lt;/span&gt; #tLogins
(strLogin)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; name &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; master.dbo.&lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;syslogins&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; isntname
= 0&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngLogCount
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;@@ROWCOUNT&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Determine
if password is null and user iis SQL Login&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'The
following logins have blank passwords'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; name &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Login
Name'&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; master.dbo.&lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;syslogins&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; password &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; isntname
= 0&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Determine
if password and name are the ssame&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter
= @lngLogCount&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; @lngCounter
&amp;lt;&amp;gt; 0&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @strName
= (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strLogin &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #tLogins &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; numID
= @lngCounter)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;UPDATE&lt;/span&gt; #tLogins&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; lngPass
= (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; PWDCOMPARE
(@strName,(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; password &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; master.dbo.&lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;syslogins&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; name
= @strName))) 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; numID
= @lngCounter&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter
= @lngCounter - 1&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'The
following logins have passwords the same as their login name'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strLogin &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Login
Name'&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #tLogins &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; lngPass
= 1&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Reset
column for next password test&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;UPDATE&lt;/span&gt; #tLogins&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; lngPass
= 0&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Determine
if password is only one characcter long&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter
= @lngLogCount&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; @lngCounter
&amp;lt;&amp;gt; 0&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter1
= 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @strName
= (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strLogin &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #tLogins &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; numID
= @lngCounter)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHILE&lt;/span&gt; @lngCounter1
&amp;lt; 256&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;UPDATE&lt;/span&gt; #tLogins&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; lngPass
= (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; PWDCOMPARE
(&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CHAR&lt;/span&gt;(@lngCounter1),(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; password &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; master.dbo.&lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;syslogins&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; name
= @strName))) 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; numID
= @lngCounter&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AND&lt;/span&gt; lngPass
&amp;lt;&amp;gt; 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter1
= @lngCounter1 + 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SET&lt;/span&gt; @lngCounter
= @lngCounter - 1&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'The
following logins have one character passwords'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; strLogin &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Login
Name'&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #tLogins &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; lngPass
= 1&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Test&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; dbo.spAuditPasswords&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;hr width="75%" color=#c0c0c0 size=1&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
And last but not least Bradley Morris has published an article about &lt;a href="http://www.sql-server-performance.com/bm_object_permission_scripts.asp"&gt;"How
to Script User and Role Object Permissions in SQL Server"&lt;/a&gt; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=4f42c907-3e39-4283-a4fb-c3e536ce2ceb" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,4f42c907-3e39-4283-a4fb-c3e536ce2ceb.aspx</comments>
      <category>Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS;Security</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=1e768aef-9ae5-4e60-9dad-2f2e73b00faa</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,1e768aef-9ae5-4e60-9dad-2f2e73b00faa.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,1e768aef-9ae5-4e60-9dad-2f2e73b00faa.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1e768aef-9ae5-4e60-9dad-2f2e73b00faa</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>SQL Server View of AD Users or Performing a SQL Distributed Query by Using ADSI</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,1e768aef-9ae5-4e60-9dad-2f2e73b00faa.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,1e768aef-9ae5-4e60-9dad-2f2e73b00faa.aspx</link>
      <pubDate>Mon, 06 Mar 2006 04:55:58 GMT</pubDate>
      <description>Being annoyed about the Reporting Services Execution Log just bringing up the domain users and having a customer without speaking usernames I searched for a solution to join Execution Log and the Active Directory to enrich the usernames to be able to identify the users.&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=1e768aef-9ae5-4e60-9dad-2f2e73b00faa"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,1e768aef-9ae5-4e60-9dad-2f2e73b00faa.aspx</comments>
      <category>Development;Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS;MS SQL Server/RS - SSRS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=96f7b063-eac4-4ae2-8242-0b791feb87cc</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,96f7b063-eac4-4ae2-8242-0b791feb87cc.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,96f7b063-eac4-4ae2-8242-0b791feb87cc.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=96f7b063-eac4-4ae2-8242-0b791feb87cc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sorry, German only...
</p>
        <p>
Auf den Seiten des <a href="http://www.sqlpass.de/" target="_blank">PASS Deutschland
e.V.</a> steht ein CommunityCast von <a href="http://blogs.msdn.com/sebweber" target="_blank">Sebastian
Weber</a> zum Thema <a href="http://www.sqlpass.de/Default.aspx?tabid=175" target="_blank">"SQL
Server 2005 - CLR Entwicklung"</a> zum Ansehen und zum Download zur Verfügung.
</p>
        <p>
Am 02.03.2006 ab 19.00 Uhr wird es ebenfalls unter dieser <a href="http://www.sqlpass.de/Default.aspx?tabid=175" target="_blank">Adresse</a> eine
Möglichkeit zum Chat mit Sebastian Weber geben, in dem entsprechende Fragen zum Thema
CLR Entwicklung gestellt werden können.
</p>
        <p>
Viel Spaß mit dem CommunityCast und herzlichen Dank an Sebastian Weber!
</p>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=96f7b063-eac4-4ae2-8242-0b791feb87cc" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>CommunityCast: SQL Server 2005 - CLR Entwicklung</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,96f7b063-eac4-4ae2-8242-0b791feb87cc.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,96f7b063-eac4-4ae2-8242-0b791feb87cc.aspx</link>
      <pubDate>Thu, 23 Feb 2006 11:03:12 GMT</pubDate>
      <description>&lt;p&gt;
Sorry,&amp;nbsp;German only...
&lt;/p&gt;
&lt;p&gt;
Auf den Seiten des &lt;a href="http://www.sqlpass.de/" target=_blank&gt;PASS Deutschland
e.V.&lt;/a&gt;&amp;nbsp;steht&amp;nbsp;ein CommunityCast von &lt;a href="http://blogs.msdn.com/sebweber" target=_blank&gt;Sebastian
Weber&lt;/a&gt; zum Thema &lt;a href="http://www.sqlpass.de/Default.aspx?tabid=175" target=_blank&gt;"SQL
Server 2005 - CLR Entwicklung"&lt;/a&gt; zum Ansehen und zum Download zur Verfügung.
&lt;/p&gt;
&lt;p&gt;
Am 02.03.2006 ab 19.00 Uhr wird es ebenfalls unter dieser &lt;a href="http://www.sqlpass.de/Default.aspx?tabid=175" target=_blank&gt;Adresse&lt;/a&gt; eine
Möglichkeit zum Chat mit Sebastian Weber geben, in dem entsprechende Fragen zum Thema
CLR Entwicklung gestellt werden können.
&lt;/p&gt;
&lt;p&gt;
Viel Spaß mit dem CommunityCast und herzlichen Dank an Sebastian Weber!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=96f7b063-eac4-4ae2-8242-0b791feb87cc" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,96f7b063-eac4-4ae2-8242-0b791feb87cc.aspx</comments>
      <category>Development;Development/.Net;Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS;PASS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=756db290-96ff-49ac-8205-3b5f93f4b565</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,756db290-96ff-49ac-8205-3b5f93f4b565.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,756db290-96ff-49ac-8205-3b5f93f4b565.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=756db290-96ff-49ac-8205-3b5f93f4b565</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Have you also moaned about setting security for your stored proc´s?<br />
I am shure, you have!<br />
;-)
</p>
        <p>
The following script should help you to set security - if you are using namespaces
für your sproc´s....
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>
            <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">exists</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">select</span> * <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">from</span> dbo.<span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">sysobjects</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">where</span> id
=<br /><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object_id</span>(N<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'[dbo].[spr_grantproc]'</span>) <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">and</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECTPROPERTY</span>(id,<br />
N<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'IsProcedure'</span>)
= 1)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">drop</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">procedure</span> [dbo].[spr_grantproc]<br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">procedure</span> spr_grantproc<br />
@login <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(50),<br />
@prefix <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(50),<br />
@<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">grant</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">bit</span><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/*
allocates the security settings to all SP´s beginning with the defined prefix
(without itself)<br />
@grant=1 grant access<br /></span></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">@grant=0
revoke access<br />
@login User-Login */</span>
            <br />
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS<br /></span>
          </span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">declare</span> @grantsql <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">as</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">sysname</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">declare</span> @action <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">as</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(6)<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (@<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">grant</span>=1)<br /></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   set</span> @action=<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'GRANT'<br /></span></span>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else<br /></span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   set</span> @action=<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'REVOKE'</span><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (@login <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">is</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">not</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">begin</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   SELECT<br />
      </span>@Action+<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
EXECUTE ON '</span> + [NAME] + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
TO '</span> + @login <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">as</span> sel<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   into<br />
      </span>#granttbl<br />
   <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">from<br />
      </span><span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SYSOBJECTS</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   WHERE<br />
      </span>TYPE = <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'P'</span><br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      AND</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEFT</span>(NAME,<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEN</span>(@prefix))
= @prefix<br /><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      AND</span> [NAME]&lt;&gt;<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'spr_grantproc'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   DECLARE</span> Cur <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CURSOR</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FOR</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   SELECT</span> sel <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> #granttbl<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   OPEN</span> Cur<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   FETCH</span> NEXT <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Cur <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">into</span> @grantsql<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">      WHILE</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">@@FETCH_STATUS</span> =
0<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            exec</span>(@grantsql)<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">            FETCH</span> NEXT <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> Cur <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">into</span> @grantsql<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">         END</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   CLOSE</span> Cur<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   DEALLOCATE</span> Cur<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">   drop</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">table</span> #granttbl<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">end</span><br /><br />
GO<br /></span>
        </p>
        <img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=756db290-96ff-49ac-8205-3b5f93f4b565" />
        <br />
        <hr />
        <p>
This weblog is sponsored by <a href="http://www.fits-consulting.de">FITS</a>. 
<br />
We support <a href="http://www.sqlpass.de">PASS Germany</a>!
</p>
      </body>
      <title>Stored Procedure for granting authorization</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,756db290-96ff-49ac-8205-3b5f93f4b565.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,756db290-96ff-49ac-8205-3b5f93f4b565.aspx</link>
      <pubDate>Wed, 04 Jan 2006 04:36:13 GMT</pubDate>
      <description>&lt;p&gt;
Have you also moaned about setting security for your stored proc´s?&lt;br&gt;
I am shure, you have!&lt;br&gt;
;-)
&lt;/p&gt;
&lt;p&gt;
The following script should help you to set security - if you are using namespaces
für your sproc´s....
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;exists&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;select&lt;/span&gt; * &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;from&lt;/span&gt; dbo.&lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;sysobjects&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;where&lt;/span&gt; id
=&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object_id&lt;/span&gt;(N&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'[dbo].[spr_grantproc]'&lt;/span&gt;) &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;and&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECTPROPERTY&lt;/span&gt;(id,&lt;br&gt;
N&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'IsProcedure'&lt;/span&gt;)
= 1)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;drop&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;procedure&lt;/span&gt; [dbo].[spr_grantproc]&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;procedure&lt;/span&gt; spr_grantproc&lt;br&gt;
@login &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(50),&lt;br&gt;
@prefix &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(50),&lt;br&gt;
@&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;grant&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bit&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;/*
allocates the security settings to all SP´s&amp;nbsp;beginning with the defined prefix
(without itself)&lt;br&gt;
@grant=1 grant access&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;@grant=0
revoke access&lt;br&gt;
@login User-Login */&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;declare&lt;/span&gt; @grantsql &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;as&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;sysname&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;declare&lt;/span&gt; @action &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;as&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(6)&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (@&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;grant&lt;/span&gt;=1)&lt;br&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;set&lt;/span&gt; @action=&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'GRANT'&lt;br&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;br&gt;
&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;set&lt;/span&gt; @action=&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'REVOKE'&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (@login &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;is&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;not&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;begin&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;@Action+&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
EXECUTE ON '&lt;/span&gt; + [NAME] + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
TO '&lt;/span&gt; + @login &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;as&lt;/span&gt; sel&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;into&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;#granttbl&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;from&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SYSOBJECTS&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;TYPE = &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'P'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AND&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEFT&lt;/span&gt;(NAME,&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEN&lt;/span&gt;(@prefix))
= @prefix&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AND&lt;/span&gt; [NAME]&amp;lt;&amp;gt;&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'spr_grantproc'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;DECLARE&lt;/span&gt; Cur &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CURSOR&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FOR&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT&lt;/span&gt; sel &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; #granttbl&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;OPEN&lt;/span&gt; Cur&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FETCH&lt;/span&gt; NEXT &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Cur &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;into&lt;/span&gt; @grantsql&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHILE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;@@FETCH_STATUS&lt;/span&gt; =
0&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;exec&lt;/span&gt;(@grantsql)&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FETCH&lt;/span&gt; NEXT &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; Cur &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;into&lt;/span&gt; @grantsql&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;END&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CLOSE&lt;/span&gt; Cur&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;DEALLOCATE&lt;/span&gt; Cur&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;drop&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;table&lt;/span&gt; #granttbl&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;end&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;/p&gt;
&gt;&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=756db290-96ff-49ac-8205-3b5f93f4b565" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
&lt;p&gt;
This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. 
&lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!
&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,756db290-96ff-49ac-8205-3b5f93f4b565.aspx</comments>
      <category>Development;Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
    <item>
      <trackback:ping>http://www.fits-consulting.de/blog/Trackback.aspx?guid=580b5d5f-4022-4b31-a508-aceb6db1e690</trackback:ping>
      <pingback:server>http://www.fits-consulting.de/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.fits-consulting.de/blog/PermaLink,guid,580b5d5f-4022-4b31-a508-aceb6db1e690.aspx</pingback:target>
      <dc:creator>Markus Fischer</dc:creator>
      <wfw:comment>http://www.fits-consulting.de/blog/CommentView,guid,580b5d5f-4022-4b31-a508-aceb6db1e690.aspx</wfw:comment>
      <wfw:commentRss>http://www.fits-consulting.de/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=580b5d5f-4022-4b31-a508-aceb6db1e690</wfw:commentRss>
      <title>Generic Paging solved with a Stored Procedure</title>
      <guid isPermaLink="false">http://www.fits-consulting.de/blog/PermaLink,guid,580b5d5f-4022-4b31-a508-aceb6db1e690.aspx</guid>
      <link>http://www.fits-consulting.de/blog/PermaLink,guid,580b5d5f-4022-4b31-a508-aceb6db1e690.aspx</link>
      <pubDate>Wed, 04 Jan 2006 02:22:20 GMT</pubDate>
      <description>I found the following code somewhere in the internet sometimes ago, but did not store the link, if someone wants to be honoreed for creation - please mail to me!&lt;img width="0" height="0" src="http://www.fits-consulting.de/blog/aggbug.ashx?id=580b5d5f-4022-4b31-a508-aceb6db1e690"/&gt;&lt;br/&gt;&lt;hr/&gt;&lt;p&gt;This weblog is sponsored by &lt;a href="http://www.fits-consulting.de"&gt;FITS&lt;/a&gt;. &lt;br&gt;
We support &lt;a href="http://www.sqlpass.de"&gt;PASS Germany&lt;/a&gt;!&lt;/p&gt;</description>
      <comments>http://www.fits-consulting.de/blog/CommentView,guid,580b5d5f-4022-4b31-a508-aceb6db1e690.aspx</comments>
      <category>Development;Development/T-SQL;MS SQL Server;MS SQL Server/RDBMS</category>
    </item>
  </channel>
</rss>