<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>I grok, therefore I am</title>
	
	<link>http://blog.3234.net</link>
	<description>Developing Data-Centric Applications</description>
	<lastBuildDate>Mon, 07 Nov 2011 19:07:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/IGrokThereforeIAm" /><feedburner:info uri="igrokthereforeiam" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>DQS Services in Denali</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/sctfEsZvCIA/</link>
		<comments>http://blog.3234.net/20111030/dqs-services-in-denali/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 18:56:09 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=348</guid>
		<description><![CDATA[Interesting article about the upcoming Data Quality Services feature in Denali. It&#8217;s worth mentioning, as it&#8217;s very similar to the Data Quality Control system that I developed (with a little inspiration from my friend) for our current data mart. In &#8230; <a href="http://blog.3234.net/20111030/dqs-services-in-denali/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Interesting article about the upcoming <a href="http://blogs.technet.com/b/dataplatforminsider/archive/2011/08/16/new-and-exciting-in-sql-server-code-name-denali-knowledge-driven-data-quality-services-dqs.aspx" target="_blank">Data Quality Services</a> feature in Denali. It&#8217;s worth mentioning, as it&#8217;s very similar to the <a href="http://www.3234.net/20091115/dataqualitycontrol/" target="_blank">Data Quality Control</a> system that I developed (with a little inspiration from my <a href="http://www.pocketjoshua.com/sql/" target="_blank">friend</a>) for our current data mart.</p>
<p>In short, what I do is run a series of data quality tests on the data every time it loads. These can then be flagged for follow-up by end-users, thus increasing the overall quality of the data in the data mart.</p>
<p>While the feature-set is not nearly as complete as the Microsoft version, it&#8217;s fun seeing something you worked on reflected in Sql Server.</p>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/sctfEsZvCIA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20111030/dqs-services-in-denali/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20111030/dqs-services-in-denali/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=dqs-services-in-denali</feedburner:origLink></item>
		<item>
		<title>XML Schema Creation in SQL Server 2005</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/J8woUGOztCc/</link>
		<comments>http://blog.3234.net/20110907/xml-schema-creation-in-sql-server-2005/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 14:18:19 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL Toolbox]]></category>
		<category><![CDATA[sql server 2005]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=340</guid>
		<description><![CDATA[Here&#8217;s an interesting approach for creating a quick and dirty schema to get you started with XML. DECLARE @schema xml SET @schema = &#40;SELECT * FROM schema.TABLE FOR XML AUTO, ELEMENTS, XMLSCHEMA&#40;'SchemaName'&#41;&#41; SELECT @schema I don&#8217;t have the source, but &#8230; <a href="http://blog.3234.net/20110907/xml-schema-creation-in-sql-server-2005/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an interesting approach for creating a quick and dirty schema to get you started with XML.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">DECLARE</span> @schema xml<br />
<span style="color: #993333; font-weight: bold;">SET</span> @schema <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> schema<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">FOR</span> XML AUTO<span style="color: #66cc66;">,</span> ELEMENTS<span style="color: #66cc66;">,</span><br />
XMLSCHEMA<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SchemaName'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @schema</div></div>
<p>I don&#8217;t have the source, but I have where I <a title="Source" href="http://forums.devx.com/showthread.php?t=169578" target="_blank">found</a> it.</p>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/J8woUGOztCc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20110907/xml-schema-creation-in-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20110907/xml-schema-creation-in-sql-server-2005/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=xml-schema-creation-in-sql-server-2005</feedburner:origLink></item>
		<item>
		<title>T-SQL Alter Statement Quirk</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/rDQr1mvYcu4/</link>
		<comments>http://blog.3234.net/20110425/t-sql-alter-statement-quirk/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 21:12:40 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=327</guid>
		<description><![CDATA[To answer a recent question to the PSSUG user group e-mail, I put together a post instead of trying to answer via e-mail. First, the question: I have a staging table. Stage_id identity Stage_File_Name nvarchar(100) AllData nvarchar(max) I load a &#8230; <a href="http://blog.3234.net/20110425/t-sql-alter-statement-quirk/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To answer a recent question to the PSSUG user group e-mail, I put together a post instead of trying to answer via e-mail.</p>
<p>First, the question:</p>
<blockquote><p>I have a staging table. </p>
<p>Stage_id identity<br />
Stage_File_Name nvarchar(100)<br />
AllData nvarchar(max)</p>
<p>I load a pipe delimited file into it. Placing the entire record into the nvarchar(max). This way I can load anything into it. </p>
<p>Instead of haveing a separate staging table for each differant file. </p>
<p>I am trying to Add the columns I need. Splitting out the file. Then moving it into the normal table for that file. </p>
<p>I have it working in a batch but cannot make it a stored procedure. </p>
<p>Alter table staging<br />
Add colmumn A char(10),<br />
B INT<br />
C DATETIME<br />
ETC&#8230;&#8230;.</p>
<p>UPDATE staging<br />
SET A = SS(ALLDATA,1,4)<br />
B<br />
C<br />
ETC&#8230;.</p>
<p>INSERT NORMAL TABLE (A,B,C,ETC&#8230;)<br />
SELECT STAging</p>
<p>Alter table staging<br />
drop column a,b,c,etc&#8230;.</p>
<p>this works well until I try to make it so I can run it via stored procedure. Eventually I would like to create a job agent. </p>
<p>Any Ideas how I can make this work. Or am I going to have to write it to create a new staging table each time and drop it. </p></blockquote>
<p>Here&#8217;s my (edited) answer, updated with working t-sql below.</p>
<blockquote><p>&#8230;Assuming I understood your question correctly, I can give you a solution, but not an explanation. Perhaps someone else can chime in on the why.</p>
<p>If you wrap the alter statements (to add the columns) and update statements (on the new columns) in separate strings, and execute using the EXEC command, you can wrap it in a stored procedure. &#8230;</p></blockquote>
<p>Here is the setup, with the script I whipped up based on the question.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">CREATE DATABASE Testing_AlterStatementFun<br />
GO<br />
<br />
USE Testing_AlterStatementFun<br />
GO<br />
<br />
IF OBJECT_ID('Foo') IS NOT NULL<br />
&nbsp;DROP TABLE Foo<br />
<br />
CREATE TABLE Foo<br />
(<br />
&nbsp; &nbsp; PK INT IDENTITY(1,1)<br />
&nbsp; &nbsp; , FK INT NOT NULL<br />
&nbsp; &nbsp; , BigData VARCHAR(MAX) NOT NULL<br />
)<br />
<br />
INSERT INTO Foo ( FK, BigData ) VALUES ( 1, 'abcdefghijklmnopqrstuvwxyz' )<br />
<br />
<br />
ALTER TABLE Foo<br />
&nbsp; &nbsp; ADD First5 VARCHAR(5)<br />
&nbsp; &nbsp; , Last5 VARCHAR(5)<br />
&nbsp; &nbsp; <br />
UPDATE Foo<br />
SET First5 = LEFT( BigData, 5 )<br />
<br />
UPDATE Foo<br />
SET Last5 = RIGHT( BigData, 5 )</div></div>
<p>The above code works as a script. Next, the part that doesn&#8217;t work. First, I recreate the table, since if you create Foo_Fail without doing that, it will see that table Foo has the referenced columns.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--Recreate and Load the table.<br />
IF OBJECT_ID('Foo') IS NOT NULL<br />
&nbsp;DROP TABLE Foo<br />
<br />
CREATE TABLE Foo<br />
(<br />
&nbsp; &nbsp; PK INT IDENTITY(1,1)<br />
&nbsp; &nbsp; , FK INT NOT NULL<br />
&nbsp; &nbsp; , BigData VARCHAR(MAX) NOT NULL<br />
)<br />
<br />
INSERT INTO Foo ( FK, BigData ) VALUES ( 1, 'abcdefghijklmnopqrstuvwxyz' )<br />
<br />
-- Can't create it, since First5 doesn't exist.<br />
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = object_id(N'[dbo].[Foo_Fail]') AND OBJECTPROPERTY(Object_id, N'IsProcedure') = 1)<br />
&nbsp; &nbsp; DROP PROCEDURE [dbo].[Foo_Fail]<br />
GO<br />
<br />
CREATE PROCEDURE [dbo].[Foo_Fail]<br />
AS<br />
<br />
&nbsp; &nbsp; ALTER TABLE Foo<br />
&nbsp; &nbsp; &nbsp; &nbsp; ADD First5 VARCHAR(5)<br />
&nbsp; &nbsp; &nbsp; &nbsp; , Last5 VARCHAR(5)<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; UPDATE Foo<br />
&nbsp; &nbsp; SET First5 = LEFT( BigData, 5 )<br />
<br />
&nbsp; &nbsp; UPDATE Foo<br />
&nbsp; &nbsp; SET Last5 = RIGHT( BigData, 5 )<br />
<br />
GO</div></div>
<p>As advertised, this fails. </p>
<p>However, this does function (it&#8217;s ugly, but it works).</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">IF EXISTS (SELECT * FROM sys.objects WHERE object_id = object_id(N'[dbo].[Foo_Pass]') AND OBJECTPROPERTY(Object_id, N'IsProcedure') = 1)<br />
&nbsp; &nbsp; DROP PROCEDURE [dbo].[Foo_Pass]<br />
GO<br />
<br />
<br />
CREATE PROCEDURE [dbo].[Foo_Pass]<br />
AS<br />
<br />
EXEC( '<br />
ALTER TABLE Foo<br />
&nbsp; &nbsp; ADD First5 VARCHAR(5)<br />
&nbsp; &nbsp; , Last5 VARCHAR(5)' )<br />
&nbsp; &nbsp; <br />
EXEC( '<br />
UPDATE Foo<br />
SET First5 = LEFT( BigData, 5 )' )<br />
<br />
EXEC( '<br />
UPDATE Foo<br />
SET Last5 = RIGHT( BigData, 5 )' )<br />
<br />
<br />
GO</div></div>
<p>Finally, here&#8217;s the script working.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">IF OBJECT_ID('Foo') IS NOT NULL<br />
&nbsp;DROP TABLE Foo<br />
<br />
CREATE TABLE Foo<br />
(<br />
&nbsp; &nbsp; PK INT IDENTITY(1,1)<br />
&nbsp; &nbsp; , FK INT NOT NULL<br />
&nbsp; &nbsp; , BigData VARCHAR(MAX) NOT NULL<br />
)<br />
<br />
INSERT INTO Foo ( FK, BigData ) VALUES ( 1, 'abcdefghijklmnopqrstuvwxyz' )<br />
<br />
EXEC [dbo].[Foo_Pass]</div></div>
<p>And finally, cleanup your mess.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">USE Master<br />
GO<br />
DROP DATABASE Testing_AlterStatementFun<br />
GO</div></div>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/rDQr1mvYcu4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20110425/t-sql-alter-statement-quirk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20110425/t-sql-alter-statement-quirk/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=t-sql-alter-statement-quirk</feedburner:origLink></item>
		<item>
		<title>Recursive Directory Scripting</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/y7GiGP9Pl_Q/</link>
		<comments>http://blog.3234.net/20110328/recursive-directory-scripting/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 12:14:06 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL Server Development]]></category>
		<category><![CDATA[SQL Toolbox]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[sql server 2005]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=316</guid>
		<description><![CDATA[Inside source control, I have scripts arranged as follows: Drive:/Base/Database/ Drive:/Base/Database/Functions Drive:/Base/Database/Proc Drive:/Base/Database/Tables Etc.. Each script stored can be run multiple times with no ill effect. For example, a table generation script first checks to see that it exists before &#8230; <a href="http://blog.3234.net/20110328/recursive-directory-scripting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Inside source control, I have scripts arranged as follows:</p>
<blockquote><p>Drive:/Base/Database/<br />
Drive:/Base/Database/Functions<br />
Drive:/Base/Database/Proc<br />
Drive:/Base/Database/Tables<br />
Etc..</p></blockquote>
<p>Each script stored can be run multiple times with no ill effect. For example, a table generation script first checks to see that it exists before running a create.</p>
<p>I was troubleshooting an issue where it seemed the source and the database were out of sync, so I needed to push everything I had to a test database to continue my troubleshooting, and I didn&#8217;t want to run each script by hand.</p>
<p>I knew about sqlcmd, and wanted to quickly script out each file to run on the target database. I also needed a list of all the files in each of those layers of directories.</p>
<p>In the windows environment, it was surprisingly difficult to accomplish a recursive search for files to run, so I had to do some Google sleuthing to figure it out.</p>
<p>There were too many sources to link them all properly, but this was patched together from all over the web. If there&#8217;s a better method, I&#8217;d love to hear about it.</p>
<p>Here are the steps I followed:</p>
<blockquote><p>- Open up a command prompt window<br />
- Navigate to the root directory where my scripts are stored (in this example: Drive:/Base/Database/)<br />
- run: for /r %d in (*.sql) do echo %d  &gt; sqlcmd_files.bat<br />
(alternatively change &gt; to &gt;&gt; to append to sqlcmd_files.bat instead of overwriting it)<br />
- Edit sqlcmd_files.bat w/ your favorite text editor<br />
- Find and Replace the Drive:\ with sqlcmd -Sserver_name -ddatabase_name -iDrive:\<br />
(this should change your lines from Drive:/Base/Database/Proc/Filename.sql to sqlcmd -Sserver_name -ddatabase_name -iDrive:\Base/Database/Proc/Filename.sql )<br />
- Save and execute.</p></blockquote>
<p>Known limitations:<br />
- Doesn&#8217;t take into account dependencies. If the tables happen to script out after a stored proc that uses that table sqlcmd will throw an error. In my case, I just ran the sqlcmd_files.bat twice. The first time laid down anything without dependencies, and the second time cleaned everything up.<br />
- Specifically looks for files with the extension &#8220;.sql&#8221;. If you use something else, adjust accordingly.<br />
- All of my paths have no spaces in them. If you do, consider wrapping in quotes around your paths.</p>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/y7GiGP9Pl_Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20110328/recursive-directory-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20110328/recursive-directory-scripting/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=recursive-directory-scripting</feedburner:origLink></item>
		<item>
		<title>Primary, Secondary, Tertiary, umm…?</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/ciDqnoGjJaM/</link>
		<comments>http://blog.3234.net/20110322/primary-secondary-tertiary-umm/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 22:03:36 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL Toolbox]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Echo Chamber]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=311</guid>
		<description><![CDATA[I recently found myself asking the question posed in the title &#8211; what comes after primary, secondary, tertiary&#8230;? I had a rough idea, based on my drum line days, and the various types of Tenor drums. However, this article lays &#8230; <a href="http://blog.3234.net/20110322/primary-secondary-tertiary-umm/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently found myself asking the question posed in the title &#8211; what comes after primary, secondary, tertiary&#8230;?</p>
<p>I had a rough idea, based on my drum line days, and the various types of <a href="http://en.wikipedia.org/wiki/Tenor_drum">Tenor drums</a>.</p>
<p>However, this article lays it out nice and neat.<br />
<a href="http://dreamingthings.blogspot.com/2006/12/what-comes-after-primary-secondary.html">Source</a></p>
<blockquote><p>1st = primary, 2nd = secondary, 3rd = tertiary, 4th = quaternary, 5th = quinary, 6th = senary, 7th = septenary, 8th = octonary, 9th = nonary, 10th = denary, 12th = duodenary and 20th = vigenary.
</p></blockquote>
<p>Personally, anything after you hit the 5th level, you might consider another pattern, since you&#8217;ll lose your audience, unless they all happen to speak Latin. </p>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/ciDqnoGjJaM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20110322/primary-secondary-tertiary-umm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20110322/primary-secondary-tertiary-umm/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=primary-secondary-tertiary-umm</feedburner:origLink></item>
		<item>
		<title>Moving Database Logins</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/rvizQ4K2gAU/</link>
		<comments>http://blog.3234.net/20110321/moving-database-logins/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 22:45:50 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL Toolbox]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[server configuration]]></category>
		<category><![CDATA[sql server 2005]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=303</guid>
		<description><![CDATA[Recently we had a database issue, that necessitated us moving logins. Here&#8217;s an article I used from Microsoft to help script the logins. The KB is specifically for 2005 -> 2008, but it will also get you login&#8217;s out of &#8230; <a href="http://blog.3234.net/20110321/moving-database-logins/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently we had a database issue, that necessitated us moving logins.</p>
<p>Here&#8217;s an article I used from Microsoft to help script the logins. The KB is specifically for 2005 -> 2008, but it will also get you login&#8217;s out of a stricken server.</p>
<p><a href="http://support.microsoft.com/kb/918992">Source</a></p>
<p>It worked really well, and I wanted to record it here for reference.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">USE</span> master<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<span style="color: #993333; font-weight: bold;">IF</span> OBJECT_ID <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'sp_hexadecimal'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> sp_hexadecimal<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> sp_hexadecimal<br />
&nbsp; &nbsp; @binvalue varbinary<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">256</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; @hexvalue <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">514</span><span style="color: #66cc66;">&#41;</span> OUTPUT<br />
<span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @charvalue <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">514</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @i <span style="color: #993333; font-weight: bold;">INT</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @<span style="color: #993333; font-weight: bold;">LENGTH</span> <span style="color: #993333; font-weight: bold;">INT</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @hexstring <span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @charvalue <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'0x'</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @i <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @<span style="color: #993333; font-weight: bold;">LENGTH</span> <span style="color: #66cc66;">=</span> DATALENGTH <span style="color: #66cc66;">&#40;</span>@binvalue<span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @hexstring <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'0123456789ABCDEF'</span><br />
WHILE <span style="color: #66cc66;">&#40;</span>@i <span style="color: #66cc66;">&lt;=</span> @<span style="color: #993333; font-weight: bold;">LENGTH</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">DECLARE</span> @tempint <span style="color: #993333; font-weight: bold;">INT</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">DECLARE</span> @firstint <span style="color: #993333; font-weight: bold;">INT</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">DECLARE</span> @secondint <span style="color: #993333; font-weight: bold;">INT</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> @tempint <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">CONVERT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">SUBSTRING</span><span style="color: #66cc66;">&#40;</span>@binvalue<span style="color: #66cc66;">,</span>@i<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> @firstint <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">FLOOR</span><span style="color: #66cc66;">&#40;</span>@tempint<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> @secondint <span style="color: #66cc66;">=</span> @tempint <span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>@firstint<span style="color: #66cc66;">*</span><span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> @charvalue <span style="color: #66cc66;">=</span> @charvalue <span style="color: #66cc66;">+</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SUBSTRING</span><span style="color: #66cc66;">&#40;</span>@hexstring<span style="color: #66cc66;">,</span> @firstint<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SUBSTRING</span><span style="color: #66cc66;">&#40;</span>@hexstring<span style="color: #66cc66;">,</span> @secondint<span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> @i <span style="color: #66cc66;">=</span> @i <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #993333; font-weight: bold;">END</span><br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> @hexvalue <span style="color: #66cc66;">=</span> @charvalue<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
&nbsp;<br />
<span style="color: #993333; font-weight: bold;">IF</span> OBJECT_ID <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'sp_help_revlogin'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> sp_help_revlogin<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> sp_help_revlogin @login_name sysname <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AS</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @name sysname<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @<span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @hasaccess <span style="color: #993333; font-weight: bold;">INT</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @denylogin <span style="color: #993333; font-weight: bold;">INT</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @is_disabled <span style="color: #993333; font-weight: bold;">INT</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @PWD_varbinary &nbsp;varbinary <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">256</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @PWD_string &nbsp;<span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">514</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @SID_varbinary varbinary <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @SID_string <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">514</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @tmpstr &nbsp;<span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @is_policy_checked <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @is_expiration_checked <span style="color: #993333; font-weight: bold;">VARCHAR</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><br />
<br />
<span style="color: #993333; font-weight: bold;">DECLARE</span> @defaultdb sysname<br />
&nbsp;<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@login_name <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">DECLARE</span> login_curs CURSOR <span style="color: #993333; font-weight: bold;">FOR</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> p<span style="color: #66cc66;">.</span>sid<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span><span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>is_disabled<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>default_database_name<span style="color: #66cc66;">,</span> l<span style="color: #66cc66;">.</span>hasaccess<span style="color: #66cc66;">,</span> l<span style="color: #66cc66;">.</span>denylogin <span style="color: #993333; font-weight: bold;">FROM</span> <br />
sys<span style="color: #66cc66;">.</span>server_principals p <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>syslogins l<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#40;</span> l<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> p<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'S'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'G'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'U'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff0000;">'sa'</span><br />
<span style="color: #993333; font-weight: bold;">ELSE</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">DECLARE</span> login_curs CURSOR <span style="color: #993333; font-weight: bold;">FOR</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> p<span style="color: #66cc66;">.</span>sid<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span><span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>is_disabled<span style="color: #66cc66;">,</span> p<span style="color: #66cc66;">.</span>default_database_name<span style="color: #66cc66;">,</span> l<span style="color: #66cc66;">.</span>hasaccess<span style="color: #66cc66;">,</span> l<span style="color: #66cc66;">.</span>denylogin <span style="color: #993333; font-weight: bold;">FROM</span> <br />
sys<span style="color: #66cc66;">.</span>server_principals p <span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span> sys<span style="color: #66cc66;">.</span>syslogins l<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#40;</span> l<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">=</span> p<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> p<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'S'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'G'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'U'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> p<span style="color: #66cc66;">.</span>name <span style="color: #66cc66;">=</span> @login_name<br />
<span style="color: #993333; font-weight: bold;">OPEN</span> login_curs<br />
<br />
FETCH <span style="color: #993333; font-weight: bold;">NEXT</span> <span style="color: #993333; font-weight: bold;">FROM</span> login_curs <span style="color: #993333; font-weight: bold;">INTO</span> @SID_varbinary<span style="color: #66cc66;">,</span> @name<span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">TYPE</span><span style="color: #66cc66;">,</span> @is_disabled<span style="color: #66cc66;">,</span> @defaultdb<span style="color: #66cc66;">,</span> @hasaccess<span style="color: #66cc66;">,</span> @denylogin<br />
<span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@@fetch_status <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; PRINT <span style="color: #ff0000;">'No login(s) found.'</span><br />
&nbsp; CLOSE login_curs<br />
&nbsp; DEALLOCATE login_curs<br />
&nbsp; <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><br />
<span style="color: #993333; font-weight: bold;">END</span><br />
<span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'/* sp_help_revlogin script '</span><br />
PRINT @tmpstr<br />
<span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'** Generated '</span> <span style="color: #66cc66;">+</span> <span style="color: #993333; font-weight: bold;">CONVERT</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">,</span> GETDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' on '</span> <span style="color: #66cc66;">+</span> @@SERVERNAME <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' */'</span><br />
PRINT @tmpstr<br />
PRINT <span style="color: #ff0000;">''</span><br />
WHILE <span style="color: #66cc66;">&#40;</span>@@fetch_status <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@@fetch_status <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp; PRINT <span style="color: #ff0000;">''</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'-- Login: '</span> <span style="color: #66cc66;">+</span> @name<br />
&nbsp; &nbsp; PRINT @tmpstr<br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@<span style="color: #993333; font-weight: bold;">TYPE</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'G'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'U'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BEGIN</span> <span style="color: #808080; font-style: italic;">-- NT authenticated account/group</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CREATE LOGIN '</span> <span style="color: #66cc66;">+</span> QUOTENAME<span style="color: #66cc66;">&#40;</span> @name <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' FROM WINDOWS WITH DEFAULT_DATABASE = ['</span> <span style="color: #66cc66;">+</span> @defaultdb <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">']'</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">BEGIN</span> <span style="color: #808080; font-style: italic;">-- SQL Server authentication</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- obtain password and sid</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @PWD_varbinary <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span> LOGINPROPERTY<span style="color: #66cc66;">&#40;</span> @name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'PasswordHash'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> varbinary <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">256</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">EXEC</span> sp_hexadecimal @PWD_varbinary<span style="color: #66cc66;">,</span> @PWD_string <span style="color: #993333; font-weight: bold;">OUT</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">EXEC</span> sp_hexadecimal @SID_varbinary<span style="color: #66cc66;">,</span>@SID_string <span style="color: #993333; font-weight: bold;">OUT</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">-- obtain password policy state</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> @is_policy_checked <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">CASE</span> is_policy_checked <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'ON'</span> <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'OFF'</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">FROM</span> sys<span style="color: #66cc66;">.</span>sql_logins <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #66cc66;">=</span> @name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SELECT</span> @is_expiration_checked <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">CASE</span> is_expiration_checked <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'ON'</span> <span style="color: #993333; font-weight: bold;">WHEN</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'OFF'</span> <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">FROM</span> sys<span style="color: #66cc66;">.</span>sql_logins <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #66cc66;">=</span> @name<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'CREATE LOGIN '</span> <span style="color: #66cc66;">+</span> QUOTENAME<span style="color: #66cc66;">&#40;</span> @name <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' WITH PASSWORD = '</span> <span style="color: #66cc66;">+</span> @PWD_string <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' HASHED, SID = '</span> <span style="color: #66cc66;">+</span> @SID_string <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', DEFAULT_DATABASE = ['</span> <span style="color: #66cc66;">+</span> @defaultdb <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">']'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span> @is_policy_checked <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> @tmpstr <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', CHECK_POLICY = '</span> <span style="color: #66cc66;">+</span> @is_policy_checked<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span> @is_expiration_checked <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BEGIN</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> @tmpstr <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">', CHECK_EXPIRATION = '</span> <span style="color: #66cc66;">+</span> @is_expiration_checked<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@denylogin <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BEGIN</span> <span style="color: #808080; font-style: italic;">-- login is denied access</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> @tmpstr <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'; DENY CONNECT SQL TO '</span> <span style="color: #66cc66;">+</span> QUOTENAME<span style="color: #66cc66;">&#40;</span> @name <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">ELSE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@hasaccess <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BEGIN</span> <span style="color: #808080; font-style: italic;">-- login exists but does not have access</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> @tmpstr <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'; REVOKE CONNECT SQL TO '</span> <span style="color: #66cc66;">+</span> QUOTENAME<span style="color: #66cc66;">&#40;</span> @name <span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@is_disabled <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">BEGIN</span> <span style="color: #808080; font-style: italic;">-- login is disabled</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">SET</span> @tmpstr <span style="color: #66cc66;">=</span> @tmpstr <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">'; ALTER LOGIN '</span> <span style="color: #66cc66;">+</span> QUOTENAME<span style="color: #66cc66;">&#40;</span> @name <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' DISABLE'</span><br />
&nbsp; &nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
&nbsp; &nbsp; PRINT @tmpstr<br />
&nbsp; <span style="color: #993333; font-weight: bold;">END</span><br />
<br />
&nbsp; FETCH <span style="color: #993333; font-weight: bold;">NEXT</span> <span style="color: #993333; font-weight: bold;">FROM</span> login_curs <span style="color: #993333; font-weight: bold;">INTO</span> @SID_varbinary<span style="color: #66cc66;">,</span> @name<span style="color: #66cc66;">,</span> @<span style="color: #993333; font-weight: bold;">TYPE</span><span style="color: #66cc66;">,</span> @is_disabled<span style="color: #66cc66;">,</span> @defaultdb<span style="color: #66cc66;">,</span> @hasaccess<span style="color: #66cc66;">,</span> @denylogin<br />
&nbsp; &nbsp;<span style="color: #993333; font-weight: bold;">END</span><br />
CLOSE login_curs<br />
DEALLOCATE login_curs<br />
<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #cc66cc;">0</span><br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<p>Then</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">EXEC</span> sp_help_revlogin</div></div>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/rvizQ4K2gAU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20110321/moving-database-logins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20110321/moving-database-logins/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=moving-database-logins</feedburner:origLink></item>
		<item>
		<title>RePost: Database development mistakes made by application developers</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/HnG6flym0eo/</link>
		<comments>http://blog.3234.net/20101213/repost-database-development-mistakes-made-by-application-developers/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 12:18:07 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL Server Development]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=293</guid>
		<description><![CDATA[Link Personally, I think this should also include database developers operating on too little sleep and/or too close of a deadline.]]></description>
			<content:encoded><![CDATA[<p><a href="http://stackoverflow.com/questions/621884/database-development-mistakes-made-by-application-developers/">Link</a></p>
<p>Personally, I think this should also include database developers operating on too little sleep and/or too close of a deadline. </p>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/HnG6flym0eo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20101213/repost-database-development-mistakes-made-by-application-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20101213/repost-database-development-mistakes-made-by-application-developers/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=repost-database-development-mistakes-made-by-application-developers</feedburner:origLink></item>
		<item>
		<title>Enable CLR</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/s5XYF9Vj5d0/</link>
		<comments>http://blog.3234.net/20101030/enable-clr/#comments</comments>
		<pubDate>Sun, 31 Oct 2010 01:21:22 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL Toolbox]]></category>
		<category><![CDATA[server configuration]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=285</guid>
		<description><![CDATA[This is just one of those things that I always forget how to do. EXEC sp_CONFIGURE 'SHOW ADVANCED OPTIONS' , '1' -- Let me change it GO RECONFIGURE GO EXEC sp_CONFIGURE 'CLR ENABLED' , '1' GO RECONFIGURE GO EXEC sp_CONFIGURE &#8230; <a href="http://blog.3234.net/20101030/enable-clr/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is just one of those things that I always forget how to do.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">EXEC</span> sp_CONFIGURE <span style="color: #ff0000;">'SHOW ADVANCED OPTIONS'</span> <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'1'</span> <span style="color: #808080; font-style: italic;">-- Let me change it</span><br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
RECONFIGURE<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<span style="color: #993333; font-weight: bold;">EXEC</span> sp_CONFIGURE <span style="color: #ff0000;">'CLR ENABLED'</span> <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'1'</span><br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
RECONFIGURE<br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
<span style="color: #993333; font-weight: bold;">EXEC</span> sp_CONFIGURE <span style="color: #ff0000;">'SHOW ADVANCED OPTIONS'</span> <span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'0'</span> <span style="color: #808080; font-style: italic;">-- Return to status quo</span><br />
<span style="color: #993333; font-weight: bold;">GO</span><br />
RECONFIGURE<br />
<span style="color: #993333; font-weight: bold;">GO</span></div></div>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/s5XYF9Vj5d0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20101030/enable-clr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20101030/enable-clr/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=enable-clr</feedburner:origLink></item>
		<item>
		<title>T-SQL Creativity</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/zsm5qqii1e0/</link>
		<comments>http://blog.3234.net/20100917/t-sql-creativity/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 22:17:11 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Echo Chamber]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=281</guid>
		<description><![CDATA[This article has little to do with useful t-sql applications &#8211; since to me, minesweeper is meant for a mouse. However, it really demonstrates a fun use of t-sql. Minesweeper in T-SQL]]></description>
			<content:encoded><![CDATA[<p>This article has little to do with useful t-sql applications &#8211; since to me, minesweeper is meant for a mouse. However, it really demonstrates a fun use of t-sql.<br />
<a href="http://www.simple-talk.com/sql/t-sql-programming/minesweeper-in-t-sql/">Minesweeper in T-SQL</a></p>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/zsm5qqii1e0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20100917/t-sql-creativity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20100917/t-sql-creativity/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=t-sql-creativity</feedburner:origLink></item>
		<item>
		<title>Reporting Services Scripting for fun and profit</title>
		<link>http://feedproxy.google.com/~r/IGrokThereforeIAm/~3/k6lx50Kh_eg/</link>
		<comments>http://blog.3234.net/20100811/reporting-services-scripting-for-fun-and-profit/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 23:53:43 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SQL Toolbox]]></category>

		<guid isPermaLink="false">http://blog.3234.net/?p=277</guid>
		<description><![CDATA[After spending too long on Google, and finally getting an appropriate answer from a colleague, I thought it wise to record this information in case someone finds themselves in a similar situation. This stackoverflow sums up my issue nicely: &#8220;I &#8230; <a href="http://blog.3234.net/20100811/reporting-services-scripting-for-fun-and-profit/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After spending too long on Google, and finally getting an appropriate answer from a <a href="http://www.pocketjoshua.com/sql">colleague</a>, I thought it wise to record this information in case someone finds themselves in a similar situation.</p>
<p>This <a href="http://stackoverflow.com/questions/88710/reporting-services-deployment">stackoverflow</a> sums up my issue nicely: &#8220;I need to create a repeatable process for deploying SQL Server Reporting Services reports. I am not in favor of using Visual Studio and or Business Development Studio to do this. The rs.exe method of scripting deployments also seems rather clunky. Does anyone have a very elegant way that they have been able to deploy reports. The key here is that I want the process to be completely automated.&#8221;</p>
<p>The current accepted answer is nice, but it goes a little too far for my taste. However, the real gem is in this <a href="http://www.sqldbatips.com/showarticle.asp?ID=62">link</a> for Reporting Service Scripter. It&#8217;s a delightfully simple utility that does as advertised. I can then take the code it generates and check it into our source control system. Our deployment software just needed to be pointed at the Windows Command Script file generated, and we were off and running.</p>
<p>Hopefully this will help out anyone else in a similar situation. </p>
<img src="http://feeds.feedburner.com/~r/IGrokThereforeIAm/~4/k6lx50Kh_eg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.3234.net/20100811/reporting-services-scripting-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.3234.net/20100811/reporting-services-scripting-for-fun-and-profit/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=reporting-services-scripting-for-fun-and-profit</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 1.271 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-07 19:00:24 -->

