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

<channel>
	<title>Code Word Hank</title>
	<atom:link href="http://codewordhank.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codewordhank.com</link>
	<description>My Way of Coding by Hank Sheldon</description>
	<lastBuildDate>Thu, 15 Jul 2010 18:27:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>I might buy the iPad 2.0</title>
		<link>http://codewordhank.com/product-reviews-and-rants/i-might-buy-the-ipad-2-0/</link>
		<comments>http://codewordhank.com/product-reviews-and-rants/i-might-buy-the-ipad-2-0/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 18:23:39 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[Product Reviews and Rants]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[front facing camera]]></category>
		<category><![CDATA[iPad 2]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone 4]]></category>

		<guid isPermaLink="false">http://codewordhank.com/uncategorized/i-might-buy-the-ipad-2-0/</guid>
		<description><![CDATA[If the next iPad is designed as a big iPhone 4 then I will say now “I WILL BUY IT”!!]]></description>
			<content:encoded><![CDATA[<p>I’ve beat up the Apple iPad many times over in my articles but I have to say, I might buy version two of the iPad.  I’ve always had a love/hate relationship with Apple products.  Their hardware for the most part has always been designed very nicely even though I stand by my articles that I think the iPad fell short for their first version.  The current iPad is just an overgrown iPod Touch 3G.  If the next iPad is designed as a big iPhone 4 then I will say now <strong>“I WILL BUY IT”</strong>!!</p>
<p>I’ve recently received my new iPhone 4.0.  It’s by far, the BEST phone I’ve ever owned.  Before this phone I owned the iPhone 3G as well as some Blackberrys. I have found that I love taking videos of my daughter.  My wife uses FaceTime a lot to show me her latest antics or just to talk to me while I’m at work.  The new folders options is just awesome (but should of been there from the beginning).  And the App Store like always is still hugely robust for all the available apps.</p>
<p><a href="http://codewordhank.com/wp-content/uploads/2010/07/iPhoneiPad.jpg"><img style="display: inline; border-width: 0px;" title="iPhoneiPad" src="http://codewordhank.com/wp-content/uploads/2010/07/iPhoneiPad_thumb.jpg" border="0" alt="iPhoneiPad" width="280" height="223" /></a></p>
<p><em><span style="font-size: xx-small;">*photo doctored for pun</span></em></p>
<p>I can live without some of the stuff in my <a href="http://codewordhank.com/product-reviews-and-rants/ipad-tablet-war/" target="_blank">previous articles</a> however version 2 of the iPad does need the front facing camera as well as the other options that the iPhone 4 has.  We want to be able to sit on the couch and FaceTime with our daughter.  I want to read the news and play my addictive game with a bigger screen.  I admit all this.  I just hope it’s my iPhone 4 on growth hormones.</p>
<p>So Hurry up Apple..  Let’s get the Bigger Younger brother to the iPhone caught up and as great.  BTW, can you make it just a little cheaper then $500 ??</p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/product-reviews-and-rants/i-might-buy-the-ipad-2-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The communication object cannot be used for communication because it is in the Faulted state</title>
		<link>http://codewordhank.com/c/the-communication-object-cannot-be-used-for-communication-because-it-is-in-the-faulted-state/</link>
		<comments>http://codewordhank.com/c/the-communication-object-cannot-be-used-for-communication-because-it-is-in-the-faulted-state/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 04:27:29 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Client]]></category>
		<category><![CDATA[Close]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=139</guid>
		<description><![CDATA[The communication object cannot be used for communication because it is in the Faulted state]]></description>
			<content:encoded><![CDATA[<p>During a connection from a WCF Client to a WCF web service, I received the following error.  There’s a pitfall with this error.  It’s not what it seems.  At first, I was looking for a Faulted State in my connection.  Usually this is because the binding cannot be found for some reason.  But then I noticed in the stack trace that it was referencing the Close() of the binding. </p>
<p><a href="http://codewordhank.com/wp-content/uploads/2010/02/image1.png"><img style="display: inline; border-width: 0px;" title="image" src="http://codewordhank.com/wp-content/uploads/2010/02/image_thumb1.png" border="0" alt="image" width="556" height="317" /></a></p>
<p>Because I had the Close in the try catch, another error was throwing the code into the catch where I had the Close() statement.  This generated this error because the connection was already closed.  To fix this and to make sure this never happens again, I suggest the following code on any close of a WCF client.</p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 441px; height: 76px; overflow: auto; border: #cecece 1px solid; padding: 5px;">
<pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><span style="color: #0000ff;">if</span> (client.State == System.ServiceModel.CommunicationState.Opened)</pre>
<pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">     client.Close();</pre>
</pre>
<pre></pre>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/c/the-communication-object-cannot-be-used-for-communication-because-it-is-in-the-faulted-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Installer XML</title>
		<link>http://codewordhank.com/product-reviews-and-rants/windows-installer-xml/</link>
		<comments>http://codewordhank.com/product-reviews-and-rants/windows-installer-xml/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 05:26:43 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[Product Reviews and Rants]]></category>
		<category><![CDATA[Windows Installer XML]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Votive]]></category>
		<category><![CDATA[Wix]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=133</guid>
		<description><![CDATA[Windows Install XML is the most powerful Installer suite I’ve ever worked with.  But it also is the hardest Install suite I’ve ever used.]]></description>
			<content:encoded><![CDATA[<p> <a title="Windows Installer XML" href="http://wix.sourceforge.net/index.html" target="_blank"><img style="display: inline; margin-left: 0px; margin-right: 0px; border-width: 0px;" title="image" src="http://codewordhank.com/wp-content/uploads/2010/02/image_thumb.png" border="0" alt="image" width="166" height="92" align="right" /></a></p>
<p> <a href="http://wix.sourceforge.net/index.html" target="_blank">Windows Installer XML</a> is the most powerful Installer suite I’ve ever worked with.  But it also is the hardest Install suite I’ve ever used.</p>
<p>WiX was the first Microsoft project to be released under the Open Source license of CPL.  It was first released in 2005.  It has been around now for quite some time and still has active weekly releases.  The framework has been used to author installs for products such as SQL Server 2005 and Office 2007. You can find a nice history of WiX at <a href="http://en.wikipedia.org/wiki/WiX" target="_blank">Wikipedia</a>.   </p>
<p>I’ve been using the Visual Studio version of Wix (called Votive) for about a year now.  I was starting a new product that would involve handing off my code to other developers.  I’ve used Wise and InstallShield in the past but the problem with these are that there are high runtime costs for each developer and some developers won’t be doing much with them except changing text and recompiling.</p>
<p>I went on a search for a good open source installer.  I came across WiX.  (&lt;joke&gt;And sometimes I wish I didn’t&lt;/joke&gt;)  I was impressed by the large packages that it was used to author.  I figured if WiX could be used for those setups, then it would be perfect for my projects.  It has turned out to be a great tool but again, I warn anyone that decides to learn WiX, don’t take it lightly.  If you aren’t a developer and if your installs will have to do anything out of the ordinary then it can be very time consuming to learn.  On a good note, I haven’t found anything I couldn’t do in WiX now that I have a good grasp of it.</p>
<p>I’m hoping to share some of WiX knowledge soon to help other developers with the learning curve of getting started with this great framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/product-reviews-and-rants/windows-installer-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IPad beat by 7 year old Tablet</title>
		<link>http://codewordhank.com/product-reviews-and-rants/ipad-beat-by-5-year-old-tablet/</link>
		<comments>http://codewordhank.com/product-reviews-and-rants/ipad-beat-by-5-year-old-tablet/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 04:15:08 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[Product Reviews and Rants]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[HP]]></category>
		<category><![CDATA[IPad]]></category>
		<category><![CDATA[Sylus Pen]]></category>
		<category><![CDATA[TC 1100]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=125</guid>
		<description><![CDATA[IPad Beat by 5 Year old Tablet]]></description>
			<content:encoded><![CDATA[<p>I love this comparison.&#160; This re-enforces <a href="http://codewordhank.com/product-reviews-and-rants/ipad-tablet-war/" target="_blank">my previous article</a> about the IPad.&#160; Hope you all enjoy.</p>
<p><a href="http://codewordhank.com/wp-content/uploads/2010/02/ip11liev.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="ip11liev" border="0" alt="ip11liev" src="http://codewordhank.com/wp-content/uploads/2010/02/ip11liev_thumb.jpg" width="493" height="339" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/product-reviews-and-rants/ipad-beat-by-5-year-old-tablet/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>What the IPad needs to win (or even enter) the Tablet war</title>
		<link>http://codewordhank.com/product-reviews-and-rants/ipad-tablet-war/</link>
		<comments>http://codewordhank.com/product-reviews-and-rants/ipad-tablet-war/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 05:31:47 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[Product Reviews and Rants]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Ideas]]></category>
		<category><![CDATA[IPad]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[Tablet]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=111</guid>
		<description><![CDATA[If Apple or any other company wants to lead the Tablet market, they need to create a revolutionary machine; not a repackaged IPod on growth hormones.]]></description>
			<content:encoded><![CDATA[<p>Apple’s IPad is the new kid on the block but it may not be the bully as some of Apple’s products have been in the past.&#160; The release of the IPad has just turned the Tablet war on to full throttle and has gotten the world&#8217;s attention.&#160;&#160; The bad news for Apple is that the IPad is probably not going to dominate the market like it’s predecessor products such as the IPhone and IPod. Apple has started the war but they already need an updated model in a year or less to compete.&#160; Here are a few ideas that I think the IPad is missing.</p>
<p><a title="Apple IPad" href="http://www.apple.com/ipad/" rel="tag" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="50yy3xam" border="0" alt="50yy3xam" align="left" src="http://codewordhank.com/wp-content/uploads/2010/01/50yy3xam_thumb.jpg" width="218" height="240" /></a></p>
<p><strong>The Pen</strong></p>
<p>Where’s the stylus pen to take notes with?&#160; No one is going to use their Notes app if they have to type each note.&#160; I want to be sitting in a business meeting or a classroom and take notes on my Tablet in lieu of a paper notebook.&#160; Imagine if Apple also let us write emails by writing.&#160; Microsoft has had software (OneNote) for years that can translate writing styles.&#160; Apple has proven that they have the software geniuses and the hardware guys to make this happen so again, where is the pen?</p>
<p><strong>Say Cheese</strong></p>
<p>Ok, so the IPad doesn’t have phone support like the IPhone.&#160; I personally thing that’s a good thing because I just can’t see me talking on a 9 inch phone however what happen to the camera that’s in the IPhone?&#160; The IPad would be perfect for Mom to Skype with her daughter or granddaughter.&#160; How about a business man doing a teleconference meeting with all members linked together through their IPad tablets.&#160; Apple could start by having online interactive IPad development classes to learn how to design apps for the IPad.</p>
<p><strong>Blue File Sharing</strong></p>
<p>No, I’m not telling you Apple should make all their Icons blue but Bluetooth would certainly improve this IPod touch.. err I mean IPad.&#160; Imagine if the new IPad had Bluetooth technology that could pick up on other IPads in the same area.&#160; Yes, you could sit in a class and share white boards with your stylus and then just push the ideas back and forth to the different IPads.&#160; How about putting your IPad up on it’s nifty charger and just bring an external keyboard close to type.&#160; The tablet could even be made into a remote control for all your electronics if Bluetooth existed.&#160; I guess the designers are trying to tell us Bluetooth is only good for phone calls.&#160; There’s no drooling for the 3rd party accessory makers on this one.</p>
<p><strong>Where Are You?</strong></p>
<p>Don’t ask this question to the IPad; it can’t answer.&#160; There’s no GPS in the IPad.&#160; So you’re sitting in the coffee shop reading the daily news on your out of town trip.&#160; You decide you would like to see all stores in walking distance of you.&#160; Well, you better go ask the girl working the cappuccino machine because your IPad can’t tell you.&#160; That is, unless you know the address then you can type it in.&#160; And don’t worry about downloading the Tom Tom app so you can have someone to talk to you because it won’t be very talkative without the GPS.</p>
<p><strong>Get Busy or be #2</strong></p>
<p>HP, Dell, and Asus already have tablets on the market or coming out in the next year.&#160; These Tablets don’t have all the listed amenities either but it’s just a matter of time before one does.&#160; Right now the consumer will have to shop around and buy one of his/her liking similar to the way we buy cell phones.&#160; If Apple or any other company wants to lead the Tablet market, they need to create a revolutionary machine; not a repackaged IPod on growth hormones.</p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/product-reviews-and-rants/ipad-tablet-war/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Clipboard Live with Windows Snipping Tool</title>
		<link>http://codewordhank.com/windows-live-plugins/clipboard-live-with-windows-snipping-tool/</link>
		<comments>http://codewordhank.com/windows-live-plugins/clipboard-live-with-windows-snipping-tool/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 05:26:51 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[Windows Live Plugins]]></category>
		<category><![CDATA[Clipboard Live]]></category>
		<category><![CDATA[Image Pasting]]></category>
		<category><![CDATA[Snipping Tool]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://codewordhank.com/uncategorized/clipboard-live-with-windows-snipping-tool/</guid>
		<description><![CDATA[Clipboard Live Paste works really well with the Windows Snipping Tool.]]></description>
			<content:encoded><![CDATA[<p>Clipboard Live Paste works really well with the Windows Snipping Tool.&#160; The Snipping Tool is located under the Accessories menu in the All Programs menu.</p>
<p>I use it by snipping a image that I want.in the blog.</p>
<p><a href="http://codewordhank.com/wp-content/uploads/2010/01/bkl3choq.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="bkl3choq" border="0" alt="bkl3choq" src="http://codewordhank.com/wp-content/uploads/2010/01/bkl3choq_thumb.jpg" width="415" height="210" /></a></p>
<p> <br clear="all">
<p>Then Mark if up if needed.</p>
<p><a href="http://codewordhank.com/wp-content/uploads/2010/01/0akgihnk.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="0akgihnk" border="0" alt="0akgihnk" align="left" src="http://codewordhank.com/wp-content/uploads/2010/01/0akgihnk_thumb.jpg" width="366" height="229" /></a></p>
<p> <br clear="all">
<p>And Copy it to the Clipboard.</p>
<p><a href="http://codewordhank.com/wp-content/uploads/2010/01/image2.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="left" src="http://codewordhank.com/wp-content/uploads/2010/01/image_thumb2.png" width="254" height="82" /></a></p>
<p> <br clear="all">
<p>Finally Click on the Clipboard Live plugin to insert the image into your blog.</p>
<p><a href="http://codewordhank.com/wp-content/uploads/2010/01/image3.png"><img title="image" border="0" alt="image" align="middle" src="http://codewordhank.com/wp-content/uploads/2010/01/image_thumb3.png" width="146" height="235" /></a></p>
<p> <br clear="all">
<p>Clipboard Live Plugin can be found at the following address:</p>
<p><a onclick="javascript:pageTracker._trackPageview(&#39;/outbound/article/gallery.live.com&#39;);" href="http://gallery.live.com/LiveItemDetail.aspx?li=326740b7-413b-4e0a-bf51-dd49258fd84a">http://gallery.live.com/LiveItemDetail.aspx?li=326740b7-413b-4e0a-bf51-dd49258fd84a</a></p>
<p>Documentation and screen shots can be found at:</p>
<p><a href="http://codewordhank.com/clipboard-live/">http://codewordhank.com/clipboard-live/</a></p>
<p>All the Pasting in this Blog Post was done with Clipboard Live.&#160; I copy and pasted pictures, and Html Fragments.&#160; I hope you find this plugin very useful for your blogging needs.&#160; If you have any issues, I am planning a version 2.0.&#160; You can report them at <a href="http://clipboardlive.codeplex.com/">http://clipboardlive.codeplex.com/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/windows-live-plugins/clipboard-live-with-windows-snipping-tool/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Clipboard Live Plugin</title>
		<link>http://codewordhank.com/windows-live-plugins/clipboard-live-plugin/</link>
		<comments>http://codewordhank.com/windows-live-plugins/clipboard-live-plugin/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 14:57:23 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[Windows Live Plugins]]></category>
		<category><![CDATA[Clipboard Live]]></category>
		<category><![CDATA[Copy HTML]]></category>
		<category><![CDATA[Copy Images]]></category>
		<category><![CDATA[Copy RTF]]></category>
		<category><![CDATA[Copy Visual Studio]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=57</guid>
		<description><![CDATA[Clipboard Live enhances the pasting abilities in Windows Live Writer. Copy and Paste Images, HTML pages, Web Images, Visual Studio Code, RTF pages, and much more right into Windows Live Writer. Never lose formatting or content again in your Pastes.]]></description>
			<content:encoded><![CDATA[<p>Clipboard Live Plugin for Windows Live Writer is now released.&#160; It can be found at the following address:</p>
<p><a title="http://gallery.live.com/LiveItemDetail.aspx?li=326740b7-413b-4e0a-bf51-dd49258fd84a" href="http://gallery.live.com/LiveItemDetail.aspx?li=326740b7-413b-4e0a-bf51-dd49258fd84a">http://gallery.live.com/LiveItemDetail.aspx?li=326740b7-413b-4e0a-bf51-dd49258fd84a</a></p>
<p>Documentation and screen shots can be found at:</p>
<p><a href="http://codewordhank.com/clipboard-live/">http://codewordhank.com/clipboard-live/</a></p>
<p>Windows Live Writer is used to write and edit this blog.&#160; I decided to make the plugin after I coudln’t paste a picture into the blog.&#160; I will be doing some blog posts about different sub project from building this plugin.&#160; So keep an eye open for them.</p>
<p>If you use Live Writer and Clipboard Live, please leave me feedback on how you like the plugin.&#160; I am planning a version 2.0 in the future.</p>
<p>&#160;</p>
<p>Clipboard Live source code is shared under the GNU License at <a title="Clipboard Live at Codeplex" href="http://clipboardlive.codeplex.com/" target="_blank">http://clipboardlive.codeplex.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/windows-live-plugins/clipboard-live-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>T3Desk &#8211; Free 3D Desktop for Windows</title>
		<link>http://codewordhank.com/product-reviews-and-rants/t3desk-free-3d-desktop-for-windows/</link>
		<comments>http://codewordhank.com/product-reviews-and-rants/t3desk-free-3d-desktop-for-windows/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 17:11:21 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[Product Reviews and Rants]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[3D Desktop]]></category>
		<category><![CDATA[Desktop Manager]]></category>
		<category><![CDATA[T3Desk]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=53</guid>
		<description><![CDATA[Review of T3Desk by Tehnif Software]]></description>
			<content:encoded><![CDATA[<p>I was playing around with a pretty cool desktop manager today.  It’s called T3Desk and made by Tehnif Software.  It looks like the company is a family owned company in Russia. </p>
<p>This app puts your windows into a 3D window on your desktop and let’s you bring them back up as you need them.  I’ve always preached that windows users should limit desktop icons so the desktop can be used as a more productive viewing canvas.  I like the way this app is starting to use it.  Best of all, it’s free.</p>
<p>Check out the link below and the picture of my desktop.</p>
<p><a href="http://tehnif.com/T3Desk.aspx">T3Desk &#8211; Free 3D Desktop for Windows</a></p>
<p> <a href="http://codewordhank.com/wp-content/uploads/2010/01/desktop.jpg" target="_blank"><img style="display: inline; border-width: 0px;" title="desktop" src="http://codewordhank.com/wp-content/uploads/2010/01/desktop_thumb.jpg" border="0" alt="desktop" width="404" height="263" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/product-reviews-and-rants/t3desk-free-3d-desktop-for-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic SQL and a Trigger Gotcha</title>
		<link>http://codewordhank.com/sql-server/dynamic-sql-and-a-trigger-gotcha/</link>
		<comments>http://codewordhank.com/sql-server/dynamic-sql-and-a-trigger-gotcha/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 19:56:00 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=32</guid>
		<description><![CDATA[Sometimes we need to do dynamic SQL.  For example, there are times when you don’t know the exact table name you need to run against so you may pass it in as a variable into a stored procedure.  Let’s look at a very simple example. Declare @tablename varchar(50) Declare @sqlTxt varchar(500) set @tablename = 'Customers' [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need to do dynamic SQL.  For example, there are times when you don’t know the exact table name you need to run against so you may pass it in as a variable into a stored procedure.  Let’s look at a very simple example.</p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 397px; height: 156px; overflow: auto; border: #cecece 1px solid; padding: 5px;">
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=Declare&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">Declare</a> @tablename <a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=varchar&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">varchar</a>(50)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=Declare&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">Declare</a> @sqlTxt <a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=varchar&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">varchar</a>(500)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=set&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">set</a> @tablename = '<span style="color: #8b0000;">Customers</span>'</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=set&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">set</a> sqlTxt = '<span style="color: #8b0000;">SELECT * FROM </span>' + @tablename</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=Exec&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">Exec</a>(sqlTxt)</pre>
</pre>
<p>In this sample, we can see that we can change the query by changing the variable @tablename.</p>
<p><em><span style="font-size: x-small;">(Note: There is much more great reading about dynamic SQL on the web.  Try this site out for much more details: </span></em><a href="http://www.sommarskog.se/dynamic_sql.html" target="_blank"><em><span style="font-size: x-small;">The curse and blessings of dynamic SQL</span></em></a>)</p>
<p>Now let’s look at dynamic SQL in a Trigger. </p>
<p><strong>BEWARE: The following code WILL give an ERROR in a Trigger.  </strong></p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 457px; height: 133px; overflow: auto; border: #cecece 1px solid; padding: 5px;">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=Declare&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">Declare</a> @tablename <a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=varchar&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">varchar</a>(50)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">Delcare @sqlTxt varchr(500)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=set&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">set</a> @sqlTxt = '<span style="color: #8b0000;">insert into </span>' + @tablename + '<span style="color: #8b0000;"> select column1, column2 from INSERTED</span>'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=Exec&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">Exec</a>(sqlTxt)</pre>
</pre>
<p>The problem is that you cannot access the internal INSERTED or DELETED temporary trigger tables when running the Exec function.  It treats the code as an external procedure and doesn’t have access to these pre-defined trigger tables.</p>
<p>However there is a workaround.  You can make true temporary tables that can be accessed through the dynamic code.  Be careful though, because by doing this method the Trigger can get heavy and slow performance on your database.</p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 470px; height: 170px; overflow: auto; border: #cecece 1px solid; padding: 5px;">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=Declare&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">Declare</a> @tablename <a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=varchar&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">varchar</a>(50)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">Delcare @sqlTxt varchr(500)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=SELECT&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">SELECT</a> * <a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=INTO&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">INTO</a> #inserted <a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=FROM&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">FROM</a> INSERTED</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=set&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">set</a> @sqlTxt = '<span style="color: #8b0000;">insert into </span>' + @tablename + '<span style="color: #8b0000;"> select column1, column2 from #inserted</span>'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"><a style="color: #0000ff;" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;siteid=us%2Fdev&amp;p=1&amp;nq=NEW&amp;qu=Exec&amp;IntlSearch=&amp;boolean=PHRASE&amp;ig=01&amp;i=09&amp;i=99">Exec</a>(sqlTxt)</pre>
</pre>
<p>You’ll notice that by making a temporary table, now our code can access the new #inserted table.  This same method can be used for DELETED as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/sql-server/dynamic-sql-and-a-trigger-gotcha/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create Table Transaction Log through Triggers</title>
		<link>http://codewordhank.com/sql-server/create-table-transaction-log-through-triggers/</link>
		<comments>http://codewordhank.com/sql-server/create-table-transaction-log-through-triggers/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 17:44:27 +0000</pubDate>
		<dc:creator>Hank</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://codewordhank.com/?p=25</guid>
		<description><![CDATA[I’ve been asked many times over the years to check for ways to log what people do on specific tables in the database.  This can be for many different reasons.  Some are for reporting purposes and others are for security purposes.  The following trigger is one I wrote that can be used on any table [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been asked many times over the years to check for ways to log what people do on specific tables in the database.  This can be for many different reasons.  Some are for reporting purposes and others are for security purposes. </p>
<p>The following trigger is one I wrote that can be used on any table and will make a logging table by a different name however it will contain all the same fields in the original table plus a few logging fields.  The new log table will store all transactions that have been done to the original table.</p>
<p>If the transaction is an Update, it will store the record’s data in the new log table.  If it’s a delete, it will store the deleted data.  If it’s an Update transaction, the trigger stores the Old data.  It does Not store the new data.  I figure the original table can be checked to see the new data.</p>
<p>You will need to replace the ##SCHEMA##, ##TRIGGERNAME##, ##TABLENAME##, and ##LOG_TABLENAME## below.  The ##LOG_TABLENAME# will be a name of a table that does not exist.  This is where all the logging will occur.</p>
<p>Without further adieu:</p>
<pre style="background-color: #fbfbfb; min-height: 40px; width: 459px; height: 487px; overflow: auto; border: #cecece 1px solid; padding: 5px;">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">SET ANSI_NULLS ON</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">GO</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">SET QUOTED_IDENTIFIER ON</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">GO</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">CREATE TRIGGER [##SCHEMA##].[##TRIGGERNAME##]</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">   ON  [##SCHEMA##].[##TABLENAME##]</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">   AFTER INSERT,DELETE,UPDATE</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">AS</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">BEGIN</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	SET NOCOUNT ON;</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	-------------------</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	-- Make Audit File of record that has been changed</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	-- Set the Table Name</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @schemaName varchar(20)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @tableName varchar(40)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @auditTableName varchar(50)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @fullTableName varchar(60)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @fullAuditTableName varchar(70)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	set @schemaName = '##SCHEMA##'</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	set @tableName = '##TABLENAME##'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	set @auditTableName = '##LOG_TABLENAME##'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	set @fullTableName = '[' + @schemaName + '].[' + @tableName + ']'</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	set @fullAuditTableName = '[' + @schemaName + '].[' + @auditTableName + ']'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	-- Check to see if this Trigger is a Insert, Update, or Delete</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @Act varchar(6)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @Del bit</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	declare @Ins bit</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	set @Del = 0</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	set @Ins = 0</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if (exists(select top 1 1 from Deleted)) set @Del = 1</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if (exists(select top 1 1 from Inserted)) set @Ins = 1</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if ((@Ins = 1) and (@Del = 1)) set @Act = 'UPDATE'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if ((@Ins = 1) and (@Del = 0)) set @Act = 'INSERT'</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if ((@Del = 1) and (@Ins = 0)) set @Act = 'DELETE'</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if ((@Ins = 0) and (@Del = 0)) return</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	-- Make Audit Table</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if (not(exists(SELECT 1 FROM sysobjects WHERE lower(xtype)='u' AND name=@auditTableName)))</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	begin</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		-- create a Temporary table containing Fields and Types of Table</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		declare @MEMTABLE Table</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		(</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			Id int Identity</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			,ColumnName sysname</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			,TypeName varchar(20)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		 )</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		-- Insert the columnNames and DataTypes</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		insert into @MEMTABLE (ColumnName, TypeName)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			select name, TYPE_NAME(xtype)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			from syscolumns</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			where id = object_id(@fullTableName)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			order by colid</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		declare @cur integer</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		declare @max integer</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		declare @sqlStr as varchar(8000)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		declare @curcol sysname</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		declare @colType as varchar(10)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		-- Setup variables</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		set @sqlStr = ''</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		set @cur=1</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		select @max = max(Id) from @MEMTABLE</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		-- Loop throu the fields and make the sql statement to add the new table</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		while @cur <span style="color: #0000ff;">&lt;</span>= @max</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		begin</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			-- Get values from MEMTABLE</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			select @curCol = ColumnName, @colType = TypeName from @MEMTABLE where id = @cur</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			-- Add Column ot Sql String</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			if (@colType = 'int') or (@colType = 'bigint') or (@colType = 'uniqueidentifier')</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			begin</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">				-- Identity or RowGuidColumn - We do not want to copy the attributes</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">				set @sqlStr = @sqlStr + ' cast([' + @curCol + '] as ' + @colType + ') as [' + @curCol + '] '</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			end</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			else begin</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">				set @sqlStr = @sqlStr + ' [' + @curCol + '] as [' + @curCol + '] '</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			end</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			if (@cur <span style="color: #0000ff;">&lt;</span>= (@max - 1)) set @sqlStr = @sqlStr + ','</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">			set @cur = @cur + 1</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		end</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		-- Add the User and Date time Fields</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		set @sqlStr = @sqlStr + ',cast(''      '' as varchar(6)) as TriggerAction, cast(GETDATE() as datetime) as TriggerDate, cast(''  '' as varchar(50)) as TriggerUser'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		-- Set up the Select statement to create the Audit Table</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		set @sqlStr = 'select Top 0 ' + @sqlStr + ' into ' + @fullAuditTableName + ' from ' + @fullTableName</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		exec(@sqlStr)</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	end</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	if (exists(SELECT 1 FROM sysobjects WHERE lower(xtype)='u' AND name=@auditTableName))</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	begin</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		declare @instrStr as varchar(8000)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		set @instrStr = null</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		if ((@Act = 'INSERT') or (@Act = 'UPDATE')) SELECT * INTO #inserted FROM inserted</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		if ((@Act = 'DELETE') or (@Act = 'UPDATE')) SELECT * INTO #deleted FROM deleted</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		if (@Act = 'INSERT') set @instrStr = 'insert into ' + @fullAuditTableName + ' select *, ''INSERT'', GETDATE(), SYSTEM_USER from #inserted'</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		if (@Act = 'DELETE') set @instrStr = 'insert into ' + @fullAuditTableName + ' select *, ''DELETE'', GETDATE(), SYSTEM_USER from #deleted'</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		if (@Act = 'UPDATE') set @instrStr = 'insert into ' + @fullAuditTableName + ' select *, ''UPDATE'', GETDATE(), SYSTEM_USER from #deleted'</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">		if (@instrStr is not null) exec(@instrStr)</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">	end</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;">END</pre>
</pre>
<p>WARNING:  Using this Trigger can cause a lot of overhead for you table and slow down production in the database.  Use it as your own risk.  It also can make the Log file grow HUGE in a short time if there’s a lot of transactions so be careful.</p>
<p>Good Luck and Happy Coding</p>
]]></content:encoded>
			<wfw:commentRss>http://codewordhank.com/sql-server/create-table-transaction-log-through-triggers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
