<feed version="0.3" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://purl.org/atom/ns#" xml:lang="en-US"><title>Todd Carrico</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/default.aspx" /><tagline type="text/html">SELECT
    Posts
FROM dbo.Blogs
WHERE AuthorFirstName = 'Todd'
AND   AuthorLastName = 'Carrico'</tagline><id>http://sqljunkies.com/WebLog/tcarrico/default.aspx</id><author><url>http://sqljunkies.com/WebLog/tcarrico/default.aspx</url></author><generator url="http://communityserver.org" version="1.0.1.50214">Community Server</generator><modified>2004-08-16T20:13:00Z</modified><entry><title>Free CodeSmith!!!</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2005/07/27/16243.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:16243</id><created>2005-07-27T02:57:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;If you read my blog, you know how much I love writing code that writes code.  CodeSmith is my favorite tool for this, and I just found a way for you to get it for free!!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/scottdockendorf/archive/2005/07/26/420584.aspx"&gt;http://weblogs.asp.net/scottdockendorf/archive/2005/07/26/420584.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;get em while you can!!&lt;/P&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=16243" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=16243</wfw:commentRss></entry><entry><title>ScriptTableData CodeSmith template that handles Text and NText data</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2005/06/28/ScriptTableData_CodeSmith_Template.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:15938</id><created>2005-06-28T06:09:00Z</created><content type="text/html" mode="escaped">I just posted a template in the &lt;a href="http://forum.codesmithtools.com/default.aspx?f=9&amp;m=6900"&gt;CodeSmith Template Share&lt;/a&gt; forum that
uses XML with sp_xml_preparedocument, OPENXML, and
sp_xml_removedocument to accurately script out data in a SQL Server
table.&lt;br&gt;
&lt;br&gt;
Some highlights of the template:&lt;br&gt;
&lt;ul&gt;
  &lt;li&gt;The original table data is copied into a new table for 
backup.&lt;/li&gt;
  &lt;li&gt;If a TargetDatabase is defined, the script will include a 
"Use" statement.&lt;/li&gt;
  &lt;li&gt;If a TargetDatabase is defined, and the 
AutoExecutescript property is true, the ouput will be executed on the 
target database&lt;/li&gt;
  &lt;li&gt;If the current table has an identity column, the seed is 
maintained.&lt;/li&gt;
  &lt;li&gt;The entire operation is handled in a Serialized Transaction.&lt;/li&gt;
&lt;/ul&gt;
This template was built and tested with CodeSmith 3.0&lt;br&gt;
&lt;br&gt;
Check it out, and give me some feedback...  how does it compare to
the template that ships with CodeSmith?  Anyone got any ideas for
enhancing this template to handle Binary data?&lt;br&gt;
&lt;br&gt;
tc&lt;br&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=15938" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=15938</wfw:commentRss></entry><entry><title>New version of CodeSmith just released.</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2005/05/16/14631.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:14631</id><created>2005-05-16T08:03:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;My favorite Code Generator just got a huge upgrade...  &lt;/P&gt;
&lt;P&gt;A &lt;A href="http://www.codesmithtools.com/"&gt;New site&lt;/A&gt; and a &lt;A href="http://www.codesmithtools.com/license.aspx"&gt;new release&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Ever wanted more time to get a project done?  This tool has saved me so much time in the last year.  After you get your templates generating your code the way you like, CodeSmith 3.0 will practically make time for you.  CodeSmith 2.6 has paid for itself many times over, and I expect that CodeSmith 3.0 will continue this trend.&lt;/P&gt;Some things I like about CodeSmith 3.0:&lt;BR&gt;
&lt;H3&gt;XML Properties&lt;/H3&gt;&lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;Generate and XSD that defines your structure, and add the property attribute to your template.  The property grid will let you pick an xml file to populate the property.  You can now create your own metadata.  Create your own mapping scheme they way you want it.&lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Code Completion&lt;/H3&gt;&lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;One of the hardest things to pick up with CodeSmith is how powerful the Schema Explorer is.  It was documented in 2.6, but with Code Completion, the learning curve is ¼ what it was in CodeSmith 2.6&lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Built In Merge Strategies&lt;/H3&gt;&lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;If you are not using Active Generation&lt;SUP&gt;1&lt;/SUP&gt;, but want more automation than Passive Generation&lt;SUP&gt;2&lt;/SUP&gt; can give you, then Merge Strategies are your ticket.  Specify regions in your code that are either replaced when the CodeSmith console is run, or are preserved. Either way, it allows the developer the freedom to blend Passive and Active code generation for the ultimate in "Your Code, Your Way"&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;CodeSmith 3.0 is well worth purchasing at twice the price.  Eric Smith doesn't know what he has.  He has really taken a good tool and made it great.&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;SUB&gt;&lt;SUP&gt;1&lt;/SUP&gt;Active Generation = The developer will not edit the code generated with the intention of re-generating the code when changes are needed&lt;/SUB&gt;&lt;BR&gt;&lt;SUB&gt;&lt;SUP&gt;2&lt;/SUP&gt;Passive Generation = The developer may edit the code generated with no intentions of re-generating if changes are needed. Changes will be made by hand&lt;/SUB&gt;&lt;/P&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=14631" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=14631</wfw:commentRss></entry><entry><title>How to implement Logical Locking</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2005/04/12/11296.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:11296</id><created>2005-04-12T11:26:00Z</created><content type="text/html" mode="escaped">&lt;p&gt;This may be an alternative to writing your own logical locking architecture.&amp;nbsp; Microsoft has provided a couple of hooks into the built in lock manager.&amp;nbsp; Using the sp_getapplock and sp_releaseapplock, developers are able to implement a custom locking strategy outside of SQL Server internals.&amp;nbsp; Here is an example of how these procs can be used:&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff"&gt;DECLARE&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;@RC &lt;font color="#0000ff"&gt;INT&lt;/font&gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @ResourceName &lt;font color="#0000ff"&gt;NVARCHAR&lt;/font&gt;(255)&lt;br /&gt;&lt;br /&gt;&lt;font color="#008000"&gt;-- the Application resource that we are trying to "lock"&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;SET &lt;/font&gt;@ResourceName = &lt;font color="#ff0000"&gt;'TableName'&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#008000"&gt;-- lock the resource so that other users must wait. We will wait for a second.&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;EXEC &lt;/font&gt;@RC = master.dbo.sp_getapplock &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Resource = @ResourceName, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @LockMode = &lt;font color="#ff0000"&gt;'Exclusive'&lt;/font&gt;, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @LockOwner = &lt;font color="#ff0000"&gt;'Session'&lt;/font&gt;, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @LockTimeout = 1000 &lt;br /&gt;&lt;br /&gt;&lt;font color="#008000"&gt;-- Possible return codes 0, 1, -1, -2, -3, -999 (see BOL [sp_getapplock] for explanations)&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;IF &lt;/font&gt;@RC &lt;font color="#0000ff"&gt;NOT IN &lt;/font&gt;(0,1)&lt;br /&gt;&lt;font color="#0000ff"&gt;BEGIN&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp; RAISERROR&lt;/font&gt;( &lt;font color="#ff0000"&gt;'Timeout getting the Resource Lock'&lt;/font&gt;, 16, 1 )&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp; GOTO &lt;/font&gt;ErrorHandler&lt;br /&gt;&lt;font color="#0000ff"&gt;END&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /** Do some work here **/&lt;br /&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- note, you should see a lock Type == App in this result set&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exec &lt;/font&gt;sp_lock&lt;br /&gt;&lt;br /&gt;&lt;font color="#008000"&gt;-- clean up as soon as another user can get access to the resource&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;EXEC &lt;/font&gt;@RC = sp_releaseapplock &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Resource = @ResourceName,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @LockOwner = &lt;font color="#ff0000"&gt;'Session'&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;ErrorHandler:&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRINT &lt;/font&gt;&lt;font color="#ff0000"&gt;'Skipped work'&lt;br /&gt;&lt;/p&gt;&lt;/font&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=11296" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=11296</wfw:commentRss></entry><entry><title>Statement to remove duplicate rows from a table</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2005/01/20/6635.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:6635</id><created>2005-01-20T13:02:00Z</created><content type="text/html" mode="escaped">&lt;p&gt;This is some code I use for removing duplicate rows from a table based on Primary Keys.&amp;nbsp; It could be easily modified for other&amp;nbsp;scenarios.&amp;nbsp; The end result is a clean table.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;CREATE TABLE &lt;/font&gt;#Dups( &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PkUniquevalue &lt;font color="#0000ff"&gt;INT IDENTITY&lt;/font&gt;(0,1) &lt;font color="#0000ff"&gt;NOT NULL PRIMARY KEY&lt;/font&gt;, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt &lt;font color="#0000ff"&gt;INT NOT NULL&lt;/font&gt;, &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BannerID &lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;INT &lt;br /&gt;&lt;/font&gt;) &lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;INSERT INTO &lt;/font&gt;#Dups ( cnt, BannerID ) &lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;SELECT &lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; COUNT&lt;/font&gt;(*), &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BannerID &lt;br /&gt;&lt;font color="#0000ff"&gt;FROM &lt;/font&gt;dbo.Banner&lt;br /&gt;&lt;font color="#0000ff"&gt;GROUP BY &lt;/font&gt;BannerID &lt;br /&gt;&lt;font color="#0000ff"&gt;HAVING COUNT&lt;/font&gt;(*) &amp;gt; 1 &lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;IF &lt;/font&gt;@@ROWCOUNT &amp;gt; 0 &lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;BEGIN &lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE &lt;/font&gt;@PkUniquevalue &lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;INT &lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE &lt;/font&gt;@RowsToKill &lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;INT&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DECLARE &lt;/font&gt;@BannerID &lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;int&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET &lt;/font&gt;@PkUniquevalue = 0&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHILE &lt;/font&gt;(1=1)&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT TOP &lt;/font&gt;1&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;@RowsToKill = cnt - 1,&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&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;&lt;/font&gt;@BannerID = BannerID,&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;@PkUniquevalue = PkUniquevalue&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM &lt;/font&gt;#Dups&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF &lt;/font&gt;@@ROWCOUNT &amp;gt; 0&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET ROWCOUNT &lt;/font&gt;@RowsToKill&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DELETE FROM &lt;/font&gt;dbo.Banner&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE &lt;/font&gt;BannerID = @BannerID&amp;nbsp;&lt;br /&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET ROWCOUNT &lt;/font&gt;0&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier" color="#0000ff" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier" color="#0000ff" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier" color="#0000ff" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BEGIN&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier" color="#0000ff" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BREAK&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;&lt;font face="Courier"&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END&amp;nbsp;&lt;br /&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DELETE FROM &lt;/font&gt;#Dups &lt;font color="#0000ff"&gt;WHERE &lt;/font&gt;PkUniquevalue = @PkUniquevalue&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;font face="Courier" size="1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; END&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;END&lt;br /&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=6635" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=6635</wfw:commentRss></entry><entry><title>@@SERVERNAME and SQL Server Instances</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2005/01/13/6248.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:6248</id><created>2005-01-13T13:55:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;I recently had an issue automating the creation of SQL Agent Jobs.&amp;nbsp; I need to set the Log File properties of the job steps, and was setting the path to a local share on the SQL Server.&amp;nbsp; No problem you say:&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;FONT color=#ff0000&gt;'\\'&lt;/FONT&gt; + &lt;FONT color=#ff00ff&gt;@@SERVERNAME&lt;/FONT&gt; + &lt;FONT color=#ff0000&gt;'\Logs'&lt;/FONT&gt;&amp;nbsp; &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;should do the trick.&lt;/P&gt;
&lt;P&gt;The problem came when&amp;nbsp;I moved the code to a named instance of SQL Server.&amp;nbsp; &lt;FONT color=#ff00ff&gt;@@SERVERNAME&lt;/FONT&gt; returns "&amp;lt;ServerName&amp;gt;\&amp;lt;InstanceName&amp;gt;".&amp;nbsp;&amp;nbsp;So&amp;nbsp;I briefly thought about parsing&amp;nbsp;@@SERVERNAME, and figured there had to be a better way.&amp;nbsp; As it turns out, there is; it is called&amp;nbsp;&lt;FONT color=#0000ff&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sa-ses_3mi1.asp" target=_blank&gt;SERVERPROPERTY&lt;/A&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#ff0000&gt;'\\'&lt;/FONT&gt; &lt;FONT color=#000000&gt;+ &lt;/FONT&gt;CONVERT&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;NVARCHAR&lt;/FONT&gt;&lt;FONT size=2&gt;(128), &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;SERVERPROPERTY&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'MachineName'&lt;/FONT&gt;&lt;FONT size=2&gt;)) + &lt;FONT color=#ff0000&gt;'\Logs'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff&gt;SERVERPROPERTY&lt;/FONT&gt; returns a sql_variant, so you might have to cast it into something you can use without type conversion issues.&lt;/P&gt;
&lt;P&gt;The information you can get with &lt;FONT color=#0000ff&gt;SERVERPROPERTY&lt;/FONT&gt; is interesting:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Collation
&lt;LI&gt;Edition
&lt;LI&gt;Engine Edition
&lt;LI&gt;InstanceName
&lt;LI&gt;IsClustered
&lt;LI&gt;IsFullTextInstalled
&lt;LI&gt;IsIntegratedSecurityOnly
&lt;LI&gt;IsSingleUser
&lt;LI&gt;IsSyncWithBackup
&lt;LI&gt;LicenseType
&lt;LI&gt;MachineName
&lt;LI&gt;NumLicenses
&lt;LI&gt;ProcessID
&lt;LI&gt;ProductVersion
&lt;LI&gt;ProductLevel
&lt;LI&gt;ServerName&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=6248" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=6248</wfw:commentRss></entry><entry><title>SQL Management Studio - Autosave == true</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/10/19/4674.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:4674</id><created>2004-10-19T10:20:00Z</created><content type="text/html" mode="escaped">&lt;p&gt;Just thought I would share some exciting (for me at least) news about SQL Server Management Studio.&amp;nbsp; While it did lock up on me, it had also made an auto save copy of the script I was working with.&amp;nbsp; When I restarted SMS Studio, it asked me if I wanted to recover the script.&lt;/p&gt;&lt;p&gt;Query analyzer would lock up me as well, but never asked me to recover script files.&amp;nbsp; Very cool feature SQL Team!!!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=4674" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=4674</wfw:commentRss></entry><entry><title>Edit and Contiue to make it into C# for VS 2005</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/10/15/4613.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:4613</id><created>2004-10-15T13:11:00Z</created><content type="text/html" mode="escaped">&lt;p&gt;Yay!!!&amp;nbsp; Edit and Continue in C#.&lt;/p&gt;&lt;p&gt;I realize this is a SQL blog, but this will benefit Database developers as well.&amp;nbsp; Read more at:&lt;br /&gt;&lt;u&gt;&lt;font color="#0000ff" size="2"&gt;&lt;a href="http://blogs.msdn.com/somasegar/archive/2004/10/15/242853.aspx"&gt;http://blogs.msdn.com/somasegar/archive/2004/10/15/242853.aspx&lt;/a&gt;&lt;/font&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;Now if we could just get the SQL Team to add Intelisense into the SQL Management Studio...&amp;nbsp;&lt;/p&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=4613" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=4613</wfw:commentRss></entry><entry><title>CodeSmith 2.6 Released</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/09/28/4376.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:4376</id><created>2004-09-28T11:28:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;&lt;FONT&gt;If you are new to code generation (even if you are not!) you need to get a copy of &lt;A href="http://www.ericjsmith.net/codesmith/getfile.aspx?id=21"&gt;CodeSmith 2.6&lt;/A&gt;.  This app is the cats meow when it comes to templated code generation.  &lt;A href="http://www.ericjsmith.net/codesmith/"&gt;Eric Smith&lt;/A&gt; has really out done himself (is it really just one guy??).  Here are the features he listed in his release email:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;- Syntax highlighting of both template and target languages.&lt;BR&gt;- Much improved Visual Studio .NET custom tool.&lt;BR&gt;- Outlining support.&lt;BR&gt;- Line modification markers.&lt;BR&gt;- CodeSmith Studio is now a single instance application.&lt;BR&gt;- Improved compiler and template execution performance.&lt;BR&gt;- Better Unicode support.&lt;BR&gt;- Tons of other minor improvements and bug fixes.&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;He left out many more, but my favorite has got to be the “Template Code Expansion”.  Imagine an ASP 3.0 page with code and HTML intermingled.  Press Ctrl+Shift+M and watch the code collapse into hidden regions just like ASP.Net.  Very cool, and CodeSmith supports code behind as well.  As matter of fact, CodeSmith allows you take advantage of the full .NET framework to help you generate _YOUR_ code.  &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Think about what ASP.Net has done for generating HTML?  Sure you could write that HTML by hand, but it really gets powerful when you can generate an HTML table row for each row in a table.  CodeSmith brings this same paradigm to code generation.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT&gt;Nothing is cooler than code that writes code, and CodeSmith is the king of code generation.  Watch out for tips on how I use CodeSmith to help me get my projects done…&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=4376" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=4376</wfw:commentRss></entry><entry><title>Great CodeSmith article</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/09/16/4261.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:4261</id><created>2004-09-16T18:22:00Z</created><content type="text/html" mode="escaped">&lt;p&gt;A buddy of mine pointed me to a great article on writing cool &lt;a href="http://www.ericjsmith.com/codesmith"&gt;CodeSmith&lt;/a&gt; templates:&lt;br /&gt;&lt;font color="#0000ff" size="2"&gt;&lt;a href="http://msdn.microsoft.com/library/en-us/dnhcvs04/html/vs04e5.asp"&gt;http://msdn.microsoft.com/library/en-us/dnhcvs04/html/vs04e5.asp&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#000000"&gt;The author does a great job of covering the basics, and then gets into more complicated issues such as sub templates and custom property editors (like for picking a file using an OpenFile dialog box instead of requiring the user to type in the path to a file).&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;Very cool read.&lt;font color="#0000ff" size="2"&gt;&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;/font&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=4261" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=4261</wfw:commentRss></entry><entry><title>Custom Transactional Replication - Part 2 "The Dirty Push"</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/08/20/3975.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:3975</id><created>2004-08-20T16:48:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;Ok,&amp;nbsp;I promised to blog about my replacement for the snapshot replication.&amp;nbsp; Well, it is not really a replacement, but more of a work around for the built in snapshot (Sorry do dissapoint. I promiss it is worth the read &amp;lt;grin&amp;gt;)&lt;/P&gt;
&lt;P&gt;In our environment, we have some large transactional tables that we replicate to a reporting environment.&amp;nbsp; We all know that the reporting environment can sometimes get less than stellar hardware.&amp;nbsp; As a result, our reporting environment was pretty fragile.&amp;nbsp; Add to that an entire company of users that were banging on it, with some pretty ugly SQL&amp;nbsp;I might add, and you end up with an environment that lends itself to needing an article to be re-pushed when you least expect it.&lt;/P&gt;
&lt;P&gt;The built in snapshot will lock your table while it does the push (Concurrent Snapshot was added after we had figured this out.&amp;nbsp; We tried the shiny new concurrent snapshot, but it didn't work until SP2&amp;nbsp;I believe.&amp;nbsp; We have not tried it&amp;nbsp;since...)&amp;nbsp; What we needed was a way to snapshot the data using an&amp;nbsp;uncommitted isolation level to keep the locks to a minimum.&amp;nbsp; The CIO gets a little peeved when you have to bring your site down to push replication to your reporting environment...&amp;nbsp; However, uncommitted isolation has it's issues too, namely duplicate records.&amp;nbsp; It is easy to&amp;nbsp;fix, just clean out the duplicates before you create your unique indexes.&lt;/P&gt;
&lt;P&gt;So we created a DTS for the table we are going to push and&amp;nbsp;use the nolock query hint&amp;nbsp;to get the data.&amp;nbsp; When moving around large amounts of data,&amp;nbsp;I like to truncate and drop the table (Dropping a table is a logged operation, Truncating is not ;) ).&amp;nbsp; Then move the data and&amp;nbsp;then recreate your indexes.&amp;nbsp; At the end of this process, you now have a DTS package that will push your data, without locking your base table.&amp;nbsp; Do not run this yet.&amp;nbsp; You need to create the subscription before pushing the data.&amp;nbsp; This allows for no gaps in the data.&amp;nbsp; If you were to push the data, then create the subscription, you would have a whole in your data if records were new or updated between the push and the creation of the subscription.&amp;nbsp; Since the push uses a dirty read, we affectionately call this a "Dirty Push".&lt;/P&gt;
&lt;P&gt;The next step is to create your publication.&amp;nbsp; I like to create one publication per article.&amp;nbsp; It makes troubleshooting and management very easy.&amp;nbsp; If you have to re-initialize an article, you have to re-initialize the publication.&amp;nbsp; Re-initializing the publication will re-push all the articles in that publication. That might get ugly in&amp;nbsp;situations where all or some of the articles are large.&amp;nbsp; After you have created your publication it is time to create your subscription(s).&lt;/P&gt;
&lt;P&gt;You will create one subscription per subscriber for your publication.&amp;nbsp; When you get to the &amp;#8220;Initialize Schema&amp;#8221; section of the wizard, select the radio button for "N&lt;U&gt;o&lt;/U&gt;, the Subscriber already has the schema and data".&amp;nbsp; This tells SQL Server to forego the snapshot and just start sending data.&amp;nbsp; We want to stop the distribution agent for that subscriber so that new rows are not being inserted at the subscriber just yet.&amp;nbsp; At this point records will start collecting in the Distribution.dbo.ms_ReplCommands table for your subscriber.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Now, we can push the data using our shiny new DTS package.&amp;nbsp; Now for those of you paying attention, we have just created another problem.&amp;nbsp; We are queuing data to go to the subscriber in ms_replCommands.&amp;nbsp; We are also going to push this same data to the subscriber in our DTS.&amp;nbsp; If you have worked with replication at all, you will recognize this real quick.&amp;nbsp; The stored procedures that SQL Server creates at the subscriber will not handle this very well.&amp;nbsp; They will try to insert data that already exists, or update records that don't exist etc.&amp;nbsp; and raise an error, effectively breaking replication.&amp;nbsp; In the next entry, I will go into detail what we do in these stored procedures to ensure that replication continues, and still maintain data integrity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=3975" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=3975</wfw:commentRss></entry><entry><title>Extended Properties, SQL 2000 and 2005</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/08/19/3954.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:3954</id><created>2004-08-19T08:30:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;I was playing around with an idea for using extended properties to hold metadata&amp;nbsp;regarding the Source Control version of an object.&amp;nbsp; We manage our DB objects in &lt;A href="http://www.sourcegear.com/vault/index.asp" target=_blank&gt;Vault&lt;/A&gt;, and it is always difficult to verify that the DB and Vault are in sync.&lt;/P&gt;
&lt;P&gt;My idea was to add&amp;nbsp;some code to the bottom of each object creation script that took the SC expanded keyword &lt;FONT color=#0000ff&gt;$Revision: $&lt;/FONT&gt; and used to it build an extended property.&amp;nbsp; Then I decided to make it work in SQL 2005 for grins :)&lt;/P&gt;
&lt;P&gt;Here is the SQL 2000 version:&lt;BR&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD bgColor=lightgrey&gt;&lt;FONT color=#0000ff size=1&gt;&lt;FONT size=2&gt;IF EXISTS&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;FONT color=#0000ff&gt;SELECT &lt;/FONT&gt;* &lt;FONT color=#0000ff&gt;FROM &lt;/FONT&gt;dbo.sysproperties &lt;FONT color=#0000ff&gt;WHERE &lt;/FONT&gt;id = &lt;FONT color=#0000ff&gt;OBJECT_ID&lt;/FONT&gt;(&lt;FONT color=#ff0000&gt;'Configuration'&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;AND name &lt;/FONT&gt;= &lt;FONT color=#ff0000&gt;'SCVersion'&lt;/FONT&gt;)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC &lt;/FONT&gt;dbo.&lt;FONT color=#a52a2a&gt;sp_dropextendedproperty&lt;/FONT&gt; N&lt;FONT color=#ff0000&gt;'SCVersion'&lt;/FONT&gt;, N&lt;FONT color=#ff0000&gt;'user'&lt;/FONT&gt;, N&lt;FONT color=#ff0000&gt;'dbo'&lt;/FONT&gt;, N&lt;FONT color=#ff0000&gt;'table'&lt;/FONT&gt;, N&lt;FONT color=#ff0000&gt;'Configuration'&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;DECLARE &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;@v &lt;FONT color=#0000ff&gt;NVARCHAR&lt;/FONT&gt;(20); &lt;FONT color=#0000ff&gt;SET &lt;/FONT&gt;@v = &lt;FONT color=#0000ff&gt;CAST&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;REPLACE&lt;/FONT&gt;(&lt;FONT color=#0000ff&gt;REPLACE&lt;/FONT&gt;(&lt;FONT color=#ff0000&gt;'$Revision: 1 $'&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;'Revision:'&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;''&lt;/FONT&gt;), &lt;FONT color=#ff0000&gt;'$'&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;''&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;AS INT&lt;/FONT&gt;)&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#0000ff&gt;&lt;FONT size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;dbo.&lt;FONT color=#a52a2a&gt;sp_addextendedproperty&lt;/FONT&gt; N&lt;FONT color=#ff0000&gt;'SCVersion'&lt;/FONT&gt;, @v, N&lt;FONT color=#ff0000&gt;'user'&lt;/FONT&gt;, N&lt;FONT color=#ff0000&gt;'dbo'&lt;/FONT&gt;, N&lt;FONT color=#ff0000&gt;'table'&lt;/FONT&gt;, N&lt;FONT color=#ff0000&gt;'Configuration'&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;BR&gt;&lt;FONT color=#006400&gt;-- SELECT * FROM dbo.sysproperties WHERE id = OBJECT_ID('Configuration') AND name = 'SCVersion'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;&lt;FONT color=#000000 size=2&gt;&lt;FONT size=3&gt;For SQL 2005:&lt;BR&gt;&lt;/FONT&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD bgColor=lightgrey&gt;&lt;FONT color=#0000ff size=2&gt;IF&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;EXISTS(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;SELECT&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;*&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;FROM&lt;/FONT&gt;&lt;FONT size=2&gt; sys&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;extended_properties &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;WHERE&lt;/FONT&gt;&lt;FONT size=2&gt; major_id &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;OBJECT_ID&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'Configuration'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;AND&lt;/FONT&gt;&lt;FONT size=2&gt; name &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'SCVersion'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC&lt;/FONT&gt;&lt;FONT size=2&gt; dbo&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT color=#a52a2a size=2&gt;sp_dropextendedproperty&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'SCVersion'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'&lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;user&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'dbo'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'table'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'Configuration'&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;BR&gt;DECLARE&lt;/FONT&gt;&lt;FONT size=2&gt; @v &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;NVARCHAR&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;20&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;);&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;SET&lt;/FONT&gt;&lt;FONT size=2&gt; @v &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;REPLACE&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;REPLACE&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'$Revision: 1 $'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'Revision:'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;''&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;),&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'$'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;''&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC&lt;/FONT&gt;&lt;FONT size=2&gt; dbo&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT color=#a52a2a size=2&gt;sp_addextendedproperty&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'SCVersion'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; @v&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'&lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;user&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'dbo'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'table'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;&lt;FONT color=#000000&gt;N&lt;/FONT&gt;'Configuration'&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;BR&gt;&lt;FONT color=#006400&gt;-- SELECT&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#006400&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT size=2&gt;*&lt;/FONT&gt;&lt;FONT size=2&gt;&amp;nbsp;FROM&lt;/FONT&gt;&lt;FONT size=2&gt; sys&lt;/FONT&gt;&lt;FONT size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;extended_properties WHERE major_id &lt;FONT size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT size=2&gt;OBJECT_ID&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT size=2&gt;'Configuration'&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT size=2&gt;AND&lt;/FONT&gt;&lt;FONT size=2&gt; name &lt;/FONT&gt;&lt;FONT size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT size=2&gt;'SCVersion'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;&lt;FONT color=#006400&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=3954" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=3954</wfw:commentRss></entry><entry><title>Cool trick with update and parameters</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/08/17/3936.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:3936</id><created>2004-08-17T12:10:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;My group thought this was pretty cool, so I thought I would share it with&amp;nbsp;the world ;)&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD bgColor=lightgrey&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;CREATE PROCEDURE&lt;/FONT&gt; _fooUpd (&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Param1 &lt;FONT color=#0000ff&gt;INT&lt;/FONT&gt; = &lt;FONT color=#0000ff&gt;NULL&lt;/FONT&gt; OUTPUT,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Param2 &lt;FONT color=#0000ff&gt;INT&lt;/FONT&gt; = &lt;FONT color=#0000ff&gt;NULL&lt;/FONT&gt; OUTPUT,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @PK &lt;FONT color=#0000ff&gt;INT&lt;/FONT&gt;&lt;BR&gt;)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#0000ff&gt;AS&lt;BR&gt;BEGIN&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; UPDATE&lt;/FONT&gt; dbo.foo &lt;FONT color=#0000ff&gt;SET&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Param1 = Col1,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; @Param2 = Col2,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Retreived = Retreived + 1&lt;BR&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE&lt;/FONT&gt; PK = @PK&lt;BR&gt;&lt;FONT color=#0000ff&gt;END&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;The idea is to perform the parameter population, and the update with the same &amp;#8220;hit&amp;#8221; to the table.&amp;nbsp; The alternative is an UPDATE follwed by&amp;nbsp;a SELECT...&amp;nbsp;&amp;nbsp;Some purists might argue that this is hard to read... I&amp;nbsp;do not&amp;nbsp;agree with that, but I thought I would take the wind out of there sails ;)&amp;nbsp; Sorry, this trick does not work for SELECT statements.&amp;nbsp; You have to select all columns into variables, or return rowsets :(&lt;/P&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=3936" width="1" height="1"&gt;</content><slash:comments>2</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=3936</wfw:commentRss></entry><entry><title>Custom Transactional Replication</title><link rel="alternate" type="text/html" href="http://sqljunkies.com/WebLog/tcarrico/archive/2004/08/16/3928.aspx" /><id>d2584c15-f6ef-46f7-a2d4-24fc0e143e76:3928</id><created>2004-08-16T20:13:00Z</created><content type="text/html" mode="escaped">&lt;P&gt;A couple of friends of mine have been asking me to blog about some of the things I have done with custom replication in SQL 2000.&amp;nbsp; I figured a good place to start would be with some basic principles about replication, and then dive deeper into the guts of what I have done over a few blog entries.&amp;nbsp; Hopefully I won&amp;#8217;t bore anyone.&amp;nbsp; This post will cover the basics of Transactional Replication.&amp;nbsp; It has been trimmed down for brevity, so please no complaints about &amp;#8220;oh you left this out&amp;#8230;&amp;#8221; you can comment about it yourself and fill it in.&lt;/P&gt;
&lt;P&gt;Microsoft SQL Server 2000 has three flavors of replication.&amp;nbsp; Snapshot, Transactional, and Merge.&amp;nbsp; For this series (if you can do that in a blog ;) I will focus on Snapshot and Transactional replication.&lt;/P&gt;
&lt;P&gt;To start with, Microsoft uses a magazine metaphor for describing the parts of replication.&amp;nbsp; You start off with a publication and add article(s).&amp;nbsp; This publication is then subscribed to, and then distributed to the particular subscribers on some schedule (yes including continuous).&lt;BR&gt;&amp;nbsp;&lt;BR&gt;After you have defined a Subscription, you must synchronize the subscriber with the publisher.&amp;nbsp; This is where the snapshot comes in.&amp;nbsp; When you create the subscription, one of the questions you are asked is whether you want to start the snapshot agent.&amp;nbsp; Selecting yes will start the agent after the wizard is finished.&amp;nbsp; The snapshot agent will script out the table, copy the script over and BCP (ok I am not sure if it is BCP, or DTS.&amp;nbsp; It gets the data there) and put down three stored procedures used by the distribution agent.&amp;nbsp; If you did not select yes, do not worry.&amp;nbsp; The distribution agent will not start sending data until it thinks the data is synchronized.&lt;/P&gt;
&lt;P&gt;Now, data gets synchronized by a couple of different methodologies.&amp;nbsp; The snapshot replication, backup and restore, or BCP.&amp;nbsp; Now I assume that Snapshot replication is the preferred method for synchronizing, but we found a few issues with it that I will go into later in the series.&amp;nbsp; Suffice to say, the distribution agent must &amp;#8220;think&amp;#8221; that the data is in sync.&amp;nbsp; When you create the subscription, you can tell SQL Server that the subscriber already has the data, and SQL Server will take your word for it.&amp;nbsp; Isn&amp;#8217;t that special&amp;#8230;&lt;/P&gt;
&lt;P&gt;While the wizard was creating the snapshot agent job, it also created a couple of other agent jobs.&amp;nbsp; The wizard also created the distribution agent job and the logreader agent job.&amp;nbsp; The logreader job does exactly what it sounds like.&amp;nbsp; It reads the transaction log and creates records in a table called ms_ReplCommands in the Distribution database.&amp;nbsp; This table is the queue that the distribution agents use to serialize the commands that get the data into the subscriber.&amp;nbsp; This job is the conduit that data will flow to the subscriber.&lt;/P&gt;
&lt;P&gt;Ok, at this point you have a rough idea of the objects involved.&amp;nbsp; At least the objects that we are going to fiddle with.&amp;nbsp; Stay tuned because I am going to blog about what I don&amp;#8217;t like about the snapshot agent, and how I get around it.&amp;nbsp; On the way you learn some cool things about replication with SQL Server 2000.&lt;BR&gt;&lt;/P&gt;&lt;img src="http://sqljunkies.com/WebLog/aggbug.aspx?PostID=3928" width="1" height="1"&gt;</content><slash:comments>0</slash:comments><wfw:commentRss>http://sqljunkies.com/WebLog/tcarrico/commentrss.aspx?PostID=3928</wfw:commentRss></entry></feed>