<?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>Quarksoft\&#039;s Notes &#187; T-SQL</title>
	<atom:link href="http://blog.quarksoft.com/category/sql-server/t-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.quarksoft.com</link>
	<description>Just another Usefulnotes.com weblog</description>
	<lastBuildDate>Wed, 03 Mar 2010 16:07:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Creating Insert Statements for SQL Server</title>
		<link>http://blog.quarksoft.com/2009/07/02/creating-insert-statements-for-sql-server/</link>
		<comments>http://blog.quarksoft.com/2009/07/02/creating-insert-statements-for-sql-server/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 11:46:55 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[David Finkelstein]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[quarksoft]]></category>
		<category><![CDATA[sql server 2005]]></category>

		<guid isPermaLink="false">http://blog.quarksoft.com/?p=76</guid>
		<description><![CDATA[Ran across an interesting approach to generating insert statements for SQL Server 2005 (and other variants).  If uses a less well known function called master.dbo.fn_varbintohexstr. The approach that was taken was to use the fn_varbintohexstr function to encode the data so you did not need to use cursors or any fancy parsing to handle unicode [...]]]></description>
			<content:encoded><![CDATA[<p>Ran across an interesting approach to <a href="http://www.sqlservercentral.com/articles/T-SQL/66987/">generating insert statements</a> for SQL Server 2005 (and other variants).  If uses a less well known function called <strong>master.dbo.fn_varbintohexstr. </strong>The approach that was taken was to use the fn_varbintohexstr function to encode the data so you did not need to use cursors or any fancy parsing to handle unicode and quotes in the generated insert statements.  I thought it was a bit clever.</p>
<p>Note: you might need to register at SQLServerCentral.com to gain access to the site to read the above linked article.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2009/07/02/creating-insert-statements-for-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating Age in T-SQL</title>
		<link>http://blog.quarksoft.com/2009/03/13/calculating-age-in-t-sql/</link>
		<comments>http://blog.quarksoft.com/2009/03/13/calculating-age-in-t-sql/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 13:17:40 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[David Finkelstein]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[quarksoft]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sql server 2005]]></category>

		<guid isPermaLink="false">http://blog.quarksoft.com/?p=50</guid>
		<description><![CDATA[Here&#8217;s a decent article on calculating the age of a person (or anything else) written by Lynn Pettis.  Discusses some pitfalls with leap years.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a decent article on <a href="http://www.sqlservercentral.com/articles/T-SQL/63351/">calculating the age</a> of a person (or anything else) written by Lynn Pettis.  Discusses some pitfalls with leap years.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2009/03/13/calculating-age-in-t-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So what do you do with all those IIS log files?</title>
		<link>http://blog.quarksoft.com/2008/11/19/so-what-do-you-do-with-all-those-iis-log-files/</link>
		<comments>http://blog.quarksoft.com/2008/11/19/so-what-do-you-do-with-all-those-iis-log-files/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 04:12:23 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[IIS Logs]]></category>
		<category><![CDATA[Import]]></category>

		<guid isPermaLink="false">http://quarksoft.wordpress.com/?p=38</guid>
		<description><![CDATA[You are responsible for one or more Windows web servers and you have all these IIS log files that you want to make some sense out of.   If you have some basic SQL skills Microsoft is making available a utility called LogParser which does a great job getting in there and allowing you to query [...]]]></description>
			<content:encoded><![CDATA[<p>You are responsible for one or more Windows web servers and you have all these <a href="http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx" target="_blank">IIS log files</a> that you want to make some sense out of.   If you have some basic SQL skills Microsoft is making available a utility called <a href="http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx" target="_blank">LogParser</a> which does a great job getting in there and allowing you to query the files directly using some basic SQL syntax.   The feature I like the best is the ability to convert the data into a SQL table for manipulation via T-SQL.</p>
<p>Here is a sample of what I did (this would all go on a single line)</p>
<p>c:\&#8221;program files&#8221;\&#8221;log parser 2.2&#8243;\LogParser -iCheckPoint:myCheckPoint.lpc -o:SQL -server:localhost -database:IISLogs -createtable:ON &#8220;SELECT * FROM ex0810*.log TO IISLogs&#8221;</p>
<p>This short command line will read in all log files that start with ex0810 and import them into a table called IISLogs.  It will also create a checkpoint file so that if you run the command again it will not import records that have already been imported.</p>
<p>How cool is that?</p>
<p>Once all the importing is done you can leverage the SQL tables using whatever methods you need to.</p>
<p>If you need any help with stuff, send us a note at support at quarksoft.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2008/11/19/so-what-do-you-do-with-all-those-iis-log-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resetting the IDENTITY counter in SQL Server T-SQL</title>
		<link>http://blog.quarksoft.com/2008/05/13/resetting-the-identity-counter-in-sql-server-t-sql/</link>
		<comments>http://blog.quarksoft.com/2008/05/13/resetting-the-identity-counter-in-sql-server-t-sql/#comments</comments>
		<pubDate>Tue, 13 May 2008 18:35:00 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[quarksoft]]></category>

		<guid isPermaLink="false">http://quarksoft.wordpress.com/?p=19</guid>
		<description><![CDATA[You&#8217;ve been there before.  You are busily testing your import routines and running up the Identity column in your main import table.  Before you know it the value is in the multi-millions and you just want to reset it back to 1.  The way to accomplish this is to use the DBCC CHECKIDENT command. For [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve been there before.  You are busily testing your import routines and running up the Identity column in your main import table.  Before you know it the value is in the multi-millions and you just want to reset it back to 1. </p>
<p><span style="color:#000000">The way to accomplish this is to use the DBCC CHECKIDENT command.</span></p>
<p>For example:</p>
<pre style="padding-left:30px">DBCC CHECKIDENT (SalesForce, reseed, 0)</pre>
<p>This assumes your table is called SalesForce and you want to start the numbering at 1.  If you wanted to start the number at 2000 you can substitute 0 with 1999.  There has been some discussion that has said if the table never had records added to it the reseed value itself will be used instead of the reseed + 1 value.  You should not need to use this statement for a &#8220;new&#8221; table.</p>
<p>Credit for this post is given to Pinal Dave over at <a href="http://sqlauthority.com/">http://sqlauthority.com/</a>.  The specific post this I am referring to is the one at this <a href="http://blog.sqlauthority.com/2007/03/15/sql-server-dbcc-reseed-table-identity-value-reset-table-identity/">page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2008/05/13/resetting-the-identity-counter-in-sql-server-t-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Helping block spam with T-SQL</title>
		<link>http://blog.quarksoft.com/2008/05/01/helping-block-spam-with-t-sql/</link>
		<comments>http://blog.quarksoft.com/2008/05/01/helping-block-spam-with-t-sql/#comments</comments>
		<pubDate>Thu, 01 May 2008 13:57:41 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[phil factor]]></category>
		<category><![CDATA[quarksoft]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://quarksoft.wordpress.com/?p=18</guid>
		<description><![CDATA[Found a great article on blocking spam using T-SQL code.  It is especially useful for blog posts and other community related sites that accept user input.  Could even be used on form comments to help block all those guys that submit endless forms on your sites.  ]]></description>
			<content:encoded><![CDATA[<p>Found a great article on <a href="http://www.simple-talk.com/community/blogs/philfactor/archive/2008/04/11/47264.aspx">blocking spam using T-SQL code</a>.  It is especially useful for blog posts and other community related sites that accept user input.  Could even be used on form comments to help block all those guys that submit endless forms on your sites.</p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2008/05/01/helping-block-spam-with-t-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick method to backup SQL Server database to workstation</title>
		<link>http://blog.quarksoft.com/2008/04/09/quick-method-to-backup-sql-server-backup-to-workstation/</link>
		<comments>http://blog.quarksoft.com/2008/04/09/quick-method-to-backup-sql-server-backup-to-workstation/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 12:53:16 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://quarksoft.wordpress.com/?p=17</guid>
		<description><![CDATA[Backup SQL Server database from a remote SQL Server to a local SQL Server]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">On the last project I was working on I did not have physical access to the SQL Server disks in order to get a copy of the backup file created using the SSMS software.   I needed to make a copy to my local SQL Server in order to do some testing before I blew away all the data on the &#8220;real&#8221; SQL Server.   SSMS does not appear to have a method to allow you to specify a network path, but T-SQL has that capability with the BACKUP command.</p>
<p class="MsoNormal">If you complete the following steps you can get a backup copy of the database on your local workstation (assuming you have SQL Server installed locally):</p>
<ol>
<li>Get the IP address of your local computer using the ipconfig command or some other method.</li>
<li>Make sure you have created a share on your computer in the location where you want the backup file to be stored.  For this example I am going to assume there is a share called BACKUP that points to C:\BACKUP (again, this share is on your local workstation, not the remote SQL Server)</li>
<li>Connect to the remote database with SSMS</li>
<li>Open a Query Window</li>
<li>Execute the following command (replace 1.1.1.1 with the IP address determined from step 1 and replace YourDatabase with the name of the database you want to backup)</li>
</ol>
<p><code>BACKUP DATABASE YourDatabase<br />
TO DISK = '\\1.1.1.1\Backup\YourDatabase.bak'<br />
WITH FORMAT,<br />
NAME = 'Full Backup of YourDatabase'</code></p>
<p>Now you can use SSMS to restore the database to your local copy of SQL Server or just keep it around in case you mess up the production database.</p>
<p>Another useful thing you can do is to schedule this and use the OSQL command line tool to execute the script as part of a development release or any other process.  There are lots of options.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2008/04/09/quick-method-to-backup-sql-server-backup-to-workstation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pivots with Dynamic Columns in SQL Server 2005</title>
		<link>http://blog.quarksoft.com/2008/01/07/pivots-with-dynamic-columns-in-sql-server-2005/</link>
		<comments>http://blog.quarksoft.com/2008/01/07/pivots-with-dynamic-columns-in-sql-server-2005/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 19:41:42 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[pivot]]></category>
		<category><![CDATA[quarksoft]]></category>
		<category><![CDATA[simple-talk.com]]></category>
		<category><![CDATA[sql server 2005]]></category>

		<guid isPermaLink="false">http://blog.quarksoft.com/2008/01/07/pivots-with-dynamic-columns-in-sql-server-2005/</guid>
		<description><![CDATA[Found a great article at www.simple-talk.com which described how to create pivot queries with dynamic column names.  It seems simple at first until you try to adjust your columns manually and then discover that you really need to implement some special code to accomplish the task.  The article Pivots with Dynamic Columns in SQL Server 2005 provides [...]]]></description>
			<content:encoded><![CDATA[<p>Found a great article at <a href="http://www.simple-talk.com/">www.simple-talk.com</a> which described how to create pivot queries with dynamic column names.  It seems simple at first until you try to adjust your columns manually and then discover that you really need to implement some special code to accomplish the task.  The article <a href="http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx">Pivots with Dynamic Columns in SQL Server 2005</a> provides just the right information to accomplish the task and saved me a ton of time trying to create the process on my own.  Great job Andras.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2008/01/07/pivots-with-dynamic-columns-in-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating Dates in SQL Server&#8230; FAST!</title>
		<link>http://blog.quarksoft.com/2007/09/17/creating-dates-in-sql-server-fast/</link>
		<comments>http://blog.quarksoft.com/2007/09/17/creating-dates-in-sql-server-fast/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 14:32:04 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.quarksoft.com/2007/09/17/creating-dates-in-sql-server-fast/</guid>
		<description><![CDATA[Found a great tip online on how to create a date in T-SQL in a very fast way.  The code looks like this: declare @year int, @month int, @day int select @year = 2006, @month = 1, @day = 16 select dateadd(month,((@Year-1900)*12)+@Month-1,@Day-1) This is especially useful when doing date comparisons in queries.  Many people use [...]]]></description>
			<content:encoded><![CDATA[<p>Found a great tip online on how to create a date in T-SQL in a very fast way.  The code looks like this:</p>
<blockquote>
<pre>declare @year int, @month int, @day int
select @year = 2006, @month = 1, @day = 16</pre>
<pre>select dateadd(month,((@Year-1900)*12)+@Month-1,@Day-1)</pre>
</blockquote>
<p>This is especially useful when doing date comparisons in queries.  Many people use the convert function, but the above code executes far faster because it does not have to do any string manipulations.  Credit should be given to Michael Valentine Jones for this tip.  More information about this tip can be found <a target="_blank" href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=66471">here</a>.  Here is some more great information on <a target="_blank" href="http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx">date manipulation for SQL Server</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.quarksoft.com/2007/09/17/creating-dates-in-sql-server-fast/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
