<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Journey to SQL Authority with Pinal Dave &#187; SQL DateTime</title>
	<atom:link href="http://blog.sqlauthority.com/category/sql-datetime/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 01:30:19 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='blog.sqlauthority.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/08e35387c05b61340e885b1763a69d9f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Journey to SQL Authority with Pinal Dave &#187; SQL DateTime</title>
		<link>http://blog.sqlauthority.com</link>
	</image>
			<item>
		<title>SQL SERVER &#8211; Get Time in Hour:Minute Format from a Datetime &#8211; Get Date Part Only from Datetime</title>
		<link>http://blog.sqlauthority.com/2009/08/06/sql-server-get-time-in-hourminute-format-from-a-datetime-get-date-part-only-from-datetime/</link>
		<comments>http://blog.sqlauthority.com/2009/08/06/sql-server-get-time-in-hourminute-format-from-a-datetime-get-date-part-only-from-datetime/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 01:30:17 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=5940</guid>
		<description><![CDATA[I have seen scores of expert developers getting perplexed with SQL Server in finding time only from datetime datatype. Let us have a quick glance look at the solution.
SQL Server 2000/2005
SELECT
CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond,
CONVERT(VARCHAR(8),GETDATE(),101) AS DateOnly
GO



SQL Server 2008
SELECT
CONVERT(TIME,GETDATE()) AS HourMinuteSecond,
CONVERT(DATE,GETDATE(),101) AS DateOnly
GO



I hope the above solution is clear to you all.
Reference : Pinal Dave (http://blog.SQLAuthority.com)
Posted in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5940&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have seen scores of expert developers getting perplexed with SQL Server in finding time only from datetime datatype. Let us have a quick glance look at the solution.</p>
<p style="text-align:justify;"><strong>SQL Server 2000/2005</strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT<br />
</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">8</span><span style="color:gray;">),</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">(),</span><span style="color:black;">108</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">HourMinuteSecond</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">8</span><span style="color:gray;">),</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">(),</span><span style="color:black;">101</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">DateOnly<br />
GO</span></code></p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/datetime2005.jpg" alt="" width="489" height="188" /><br />
</span>
</p>
<p style="text-align:justify;"><strong>SQL Server 2008</strong></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT<br />
</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:black;">TIME</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) </span><span style="color:blue;">AS </span><span style="color:black;">HourMinuteSecond</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:black;">DATE</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">(),</span><span style="color:black;">101</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">DateOnly<br />
GO</span></code></p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/datetime2008.jpg" alt="" width="413" height="184" /><br />
</span>
</p>
<p style="text-align:justify;">I hope the above solution is clear to you all.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.SQLAuthority.com</a>)</strong></p>
Posted in Pinal Dave, SQL, SQL Authority, SQL DateTime, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/5940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/5940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/5940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/5940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/5940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/5940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/5940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/5940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/5940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/5940/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=5940&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/08/06/sql-server-get-time-in-hourminute-format-from-a-datetime-get-date-part-only-from-datetime/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/datetime2005.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/datetime2008.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Find Last Date Time Updated for Any Table</title>
		<link>http://blog.sqlauthority.com/2009/05/09/sql-server-find-last-date-time-updated-for-any-table/</link>
		<comments>http://blog.sqlauthority.com/2009/05/09/sql-server-find-last-date-time-updated-for-any-table/#comments</comments>
		<pubDate>Sat, 09 May 2009 01:30:17 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[Readers Question]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4940</guid>
		<description><![CDATA[I just received an email from one of my regular readers who is curious to know if there is any way to find out when a table is recently updated. I was ready with my answer! I promptly suggested him that if a table contains UpdatedDate or ModifiedDate date column with default together with value [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4940&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I just received an email from one of my regular readers who is curious to know if there is any way to find out when a table is recently updated. I was ready with my answer! I promptly suggested him that if a table contains UpdatedDate or ModifiedDate date column with default together with value GETDATE(), he should make use of it. On close observation the table is not required to keep history when any row is inserted. However, the sole prerequisite is to be aware of when any table has been updated. That’s it!</p>
<p style="text-align:justify;">If a user wants to finds out when was the last table updated he can query dynamic management view (dmv) &#8211; sys.dm_db_index_usage_stats and easily figure out when was the table updated last. Let us comprehend this example by creating a table and updating it. We can use dmv to determine when it was updated last.</p>
<p><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">CREATE TABLE </span><span style="color:black;">Test<br />
</span><span style="color:gray;">(</span><span style="color:black;">ID </span><span style="color:blue;">INT</span><span style="color:gray;">,<br />
</span><span style="color:black;">COL </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">100</span><span style="color:gray;">))<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:black;">Test<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:red;">'First'<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">2</span><span style="color:gray;">,</span><span style="color:red;">'Second'<br />
</span><span style="color:black;">GO</span></code></p>
<p style="text-align:justify;">Now we have created a table and populated it with data. Next, we will run the following query to find out when it was last updated.</p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">OBJECT_NAME</span><span style="color:gray;">(</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">DatabaseName</span><span style="color:gray;">, </span><span style="color:black;">last_user_update</span><span style="color:gray;">,*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_db_index_usage_stats<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">database_id </span><span style="color:blue;">= </span><span style="color:magenta;">DB_ID</span><span style="color:gray;">( </span><span style="color:red;">'AdventureWorks'</span><span style="color:gray;">)<br />
AND </span><span style="color:magenta;">OBJECT_ID</span><span style="color:blue;">=</span><span style="color:magenta;">OBJECT_ID</span><span style="color:gray;">(</span><span style="color:red;">'test'</span><span style="color:gray;">)</span></code></p>
<p style="text-align:justify;">Running query provides accurate details of when was  the table last updated. If WHERE condition is entirely removed it will provide details of the entire database.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/lastupdated.jpg" alt="" width="500" height="502" /></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (<a href="http://blog.sqlauthority.com/" target="_blank">http://blog.sqlauthority.com</a>)</strong></p>
Posted in Pinal Dave, Readers Question, SQL, SQL Authority, SQL DateTime, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/4940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/4940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/4940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/4940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/4940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/4940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/4940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/4940/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/4940/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/4940/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=4940&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/05/09/sql-server-find-last-date-time-updated-for-any-table/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/lastupdated.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Time Delay While Running T-SQL Query &#8211; WAITFOR Introduction</title>
		<link>http://blog.sqlauthority.com/2009/01/03/sql-server-time-delay-while-running-t-sql-query-waitfor-introduction/</link>
		<comments>http://blog.sqlauthority.com/2009/01/03/sql-server-time-delay-while-running-t-sql-query-waitfor-introduction/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 01:30:08 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1947</guid>
		<description><![CDATA[Today we will look at one very small but interesting feature of SQL Server. Please note that this is not much known feature of SQL Server. In SQL Server sometime there are requirement when T-SQL script has to wait for some time before executing next statement. It is quite common that developers depends on application [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1947&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Today we will look at one very small but interesting feature of SQL Server. Please note that this is not much known feature of SQL Server. In SQL Server sometime there are requirement when T-SQL script has to wait for some time before executing next statement. It is quite common that developers depends on application to take over this delay issue. However, SQL Server itself has very strong time management function of WAITFOR. Let us see two usage of WAITFOR clause.</p>
<p style="text-align:justify;">Official explanation of WAITFOR clause from Book Online is &#8220;Blocks the execution of a batch, stored procedure, or transaction until a specified time or time interval is reached, or a specified statement modifies or returns at least one row.&#8221;</p>
<p style="text-align:justify;"><strong>Option 1 : Waitfor Delay in executing T-SQL</strong><br />
T-SQL runs after particular delay is completed.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">() </span><span style="color:black;">CurrentTime<br />
</span><span style="color:blue;">WAITFOR </span><span style="color:black;">DELAY </span><span style="color:red;">'00:00:05' </span><span style="color:green;">---- 5 Second Delay<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">() </span><span style="color:black;">CurrentTime</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/bimg/waitfor1.jpg" alt="" width="400" height="250" /></p>
<p style="text-align:justify;"><strong>Option 2 : Waitfor Time in executing T-SQL</strong><br />
T-SQL runs after particular time has arrived.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@MyDateTime </span><span style="color:black;">DATETIME<br />
</span><span style="color:green;">/* Add 5 seconds to current time so<br />
system waits for 5 seconds*/<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@MyDateTime </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">s</span><span style="color:gray;">,</span><span style="color:black;">5</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">())<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">() </span><span style="color:black;">CurrentTime<br />
</span><span style="color:blue;">WAITFOR </span><span style="color:black;">TIME </span><span style="color:#434343;">@MyDateTime<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">() </span><span style="color:black;">CurrentTime </span></code>
</p>
<p style="text-align:justify;"><span style="color:black;"><img class="alignnone" src="http://www.pinaldave.com/bimg/waitfor2.jpg" alt="" width="400" height="300" /></span></p>
<p style="text-align:justify;"><span style="color:black;">Reference : <strong>Pinal Dave (<a href="http://blog.SQLAuthority.com" target="_blank">http://blog.SQLAuthority.com</a>)</strong><br />
</span></p>
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL DateTime, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQL Utility, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1947/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1947/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1947/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1947&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2009/01/03/sql-server-time-delay-while-running-t-sql-query-waitfor-introduction/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/bimg/waitfor1.jpg" medium="image" />

		<media:content url="http://www.pinaldave.com/bimg/waitfor2.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Retrieve &#8211; Select Only Date Part From DateTime &#8211; Best Practice &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2008/10/18/sql-server-retrieve-select-only-date-part-from-datetime-best-practice-part-2/</link>
		<comments>http://blog.sqlauthority.com/2008/10/18/sql-server-retrieve-select-only-date-part-from-datetime-best-practice-part-2/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 01:30:28 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1383</guid>
		<description><![CDATA[A year ago I wrote post about SQL SERVER &#8211; Retrieve &#8211; Select Only Date Part From DateTime &#8211; Best Practice where I have discussed two different methods of getting datepart from datetime.

Method 1:
SELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))
Method 2:
SELECT CONVERT(VARCHAR(10),GETDATE(),111)

I have summarized my post suggesting that either method works fine and I prefer to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1383&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">A year ago I wrote post about <a href="http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/" target="_blank">SQL SERVER &#8211; Retrieve &#8211; Select Only Date Part From DateTime &#8211; Best Practice</a> where I have discussed two different methods of getting datepart from datetime.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/datetimecs2.gif" alt="" width="382" height="395" /></p>
<p style="text-align:justify;">Method 1:<br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">D</span><span style="color:gray;">, </span><span style="color:black;">0</span><span style="color:gray;">, </span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">D</span><span style="color:gray;">, </span><span style="color:black;">0</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()))</span></code></p>
<p style="text-align:justify;">Method 2:<br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">),</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">(),</span><span style="color:black;">111</span><span style="color:gray;">)</span></code>
</p>
<p style="text-align:justify;">I have summarized my post suggesting that either method works fine and I prefer to use Method 2. However, with additional tests and looking at SQL Server internals very carefully, I want to suggest that Method 1 is better in terms of performance. While running on GETDATE() both of the above functions are equally fast and efficient. However, when above query is ran on very large data table performance different is visible.</p>
<p style="text-align:justify;">For testing purpose I have ran few queries where I am getting same result.</p>
<p style="text-align:justify;">Run Following query 10 times with client statistics on ( Shift+Alter+S) in SSMS.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">, </span><span style="color:black;">0</span><span style="color:gray;">, </span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">, </span><span style="color:black;">0</span><span style="color:gray;">, </span><span style="color:black;">StartDate</span><span style="color:gray;">))<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.WorkOrder<br />
GO</span></code>
</p>
<p style="text-align:justify;">Now run another query 10 times with client statistics on.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks<br />
GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">),</span><span style="color:black;">StartDate</span><span style="color:gray;">,</span><span style="color:black;">111</span><span style="color:gray;">)<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">Production.WorkOrder<br />
GO</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/datetimecs1.gif" alt="" width="382" height="395" /></p>
<p style="text-align:justify;">While looking at the average of statistics in it is clear that first query with DATEADD is much more efficient.</p>
<p style="text-align:justify;">Let us compare both of the above script together and see the client statistics.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/datetimecs.gif" alt="" width="549" height="580" /></p>
<p style="text-align:justify;">While comparing Numbers of Bytes sent across client and server as well client processing time, and total execution time in all case DATEADD is better. I suggest all my readers to use DATEADD when only DATEPART is required.</p>
<p style="text-align:justify;">If you are using SQL Server 2008 it has new DATE datatype which does not have time part. I suggest to use DATE datatype or TIME datatype for users of SQL Server 2008. Read more <a href="http://blog.sqlauthority.com/2007/12/23/sql-server-2008-new-datatypes-date-and-time/" target="_blank">SQL SERVER &#8211; 2008 &#8211; New DataTypes DATE and TIME</a><a href="http://blog.sqlauthority.com/2007/12/23/sql-server-2008-new-datatypes-date-and-time/" target="_blank">.</a></p>
<p style="text-align:justify;">If you want your date in any other format refer the UDF <a href="http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions/" target="_blank">SQL SERVER &#8211; Get Date Time in Any Format &#8211; UDF &#8211; User Defined Functions</a>.</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Best Practices, Pinal Dave, SQL, SQL Authority, SQL DateTime, SQL Function, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1383/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1383&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/10/18/sql-server-retrieve-select-only-date-part-from-datetime-best-practice-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/datetimecs2.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/datetimecs1.gif" medium="image" />

		<media:content url="http://www.pinaldave.com/blogfolder/datetimecs.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download</title>
		<link>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/</link>
		<comments>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 01:30:39 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL Data Storage]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLAuthority]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL XML]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1134</guid>
		<description><![CDATA[Download SQL Server 2008 Interview Questions and Answers Complete List
Interview is very important event for any person. A good interview leads to good career if candidate is willing to learn. I always enjoy interview questions and answers series. This is my very humble attempt to write SQL Server 2008 interview questions and answers. SQL Server [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1134&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-2008-Download-Interview-Questions-and-Answers"><strong>Download SQL Server 2008 Interview Questions and Answers Complete List</strong></a></h2>
<p style="text-align:justify;">Interview is very important event for any person. A good interview leads to good career if candidate is willing to learn. I always enjoy interview questions and answers series. This is my very humble attempt to write SQL Server 2008 interview questions and answers. SQL Server is very large subject and not everything is usually asked in interview. In interview what matters the most is <strong>conceptual knowledge</strong> and <strong>learning attitude</strong>.</p>
<p style="text-align:justify;">I have listed all the series in this post so that it can be easily downloaded and used. All the questions are collected and listed in one PDF which is here to download. If you have any question or if you want to add to any of the question please send me mail or write a comment.</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/12/sql-server-2008-interview-questions-and-answers-part-1/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 1</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/13/sql-server-2008-interview-questions-and-answers-part-2/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 2</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/14/sql-server-2008-interview-questions-and-answers-part-3/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 3</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/15/sql-server-2008-interview-questions-and-answers-part-4/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 4</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/16/sql-server-2008-interview-questions-and-answers-part-5/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 5</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/17/sql-server-2008-interview-questions-and-answers-part-6/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 6</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/18/sql-server-2008-interview-questions-and-answers-part-7/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 7</strong></a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2008/09/19/sql-server-2008-interview-questions-and-answers-part-8/"><strong>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 8</strong></a></p>
<h2 style="text-align:justify;"><a href="http://www.pinaldave.com/best-sql-server-download.cfm?download=SQL-SERVER-2008-Download-Interview-Questions-and-Answers"><strong>Download SQL Server 2008 Interview Questions and Answers Complete List</strong></a></h2>
<p style="text-align:justify;">
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
Posted in Database, Pinal Dave, SQL, SQL Authority, SQL Constraint and Keys, SQL Cursor, SQL Data Storage, SQL DateTime, SQL Documentation, SQL Download, SQL Error Messages, SQL Function, SQL Index, SQL Interview Questions and Answers, SQL Joins, SQL Performance, SQL Query, SQL Scripts, SQL Security, SQL Server, SQL Server DBCC, SQL Stored Procedure, SQL Tips and Tricks, SQL Trigger, SQL Utility, SQLAuthority, T SQL, Technology Tagged: SQL XML <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1134&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers &#8211; Part 6</title>
		<link>http://blog.sqlauthority.com/2008/09/17/sql-server-2008-interview-questions-and-answers-part-6/</link>
		<comments>http://blog.sqlauthority.com/2008/09/17/sql-server-2008-interview-questions-and-answers-part-6/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 01:30:05 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Data Storage]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[SQLAuthority]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=1008</guid>
		<description><![CDATA[SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download
3) Questions of SQL SERVER 2008
What are the basic functions for master, msdb, model, tempdb and resource databases?
The master database holds information for all databases located on the SQL Server instance and is theglue that holds the engine together. Because SQL Server cannot start [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1008&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2 style="text-align:justify;"><strong><a href="http://blog.sqlauthority.com/2008/09/20/sql-server-2008-interview-questions-and-answers-complete-list-download/" target="_blank">SQL SERVER &#8211; 2008 &#8211; Interview Questions and Answers Complete List Download</a></strong></h2>
<p style="text-align:justify;"><strong>3) </strong><strong>Questions of SQL SERVER 2008</strong></p>
<p style="text-align:justify;"><strong>What are the basic functions for master, msdb, model, tempdb and resource databases?</strong></p>
<p style="text-align:justify;"><em>The <strong>master</strong> database </em>holds information for all databases located on the SQL Server instance and is theglue that holds the engine together. Because SQL Server cannot start without a functioning masterdatabase, you must administer this database with care.</p>
<p style="text-align:justify;"><em>The <strong>msdb</strong> database </em>stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping.</p>
<p style="text-align:justify;"><em>The <strong>tempdb</strong> </em>holds temporary objects such as global and local temporary tables and stored procedures.</p>
<p style="text-align:justify;"><em>The <strong>model</strong></em> is essentially a template database used in the creation of any new user database created in the instance.</p>
<p style="text-align:justify;"><em>The <strong>resoure</strong> Database </em>is a read-only database that contains all the system objects that are included with SQL Server. SQL Server system objects, such as sys.objects, are physically persisted in the Resource database, but they logically appear in the sys schema of every database. The Resource database does not contain user data or user metadata.</p>
<p style="text-align:justify;"><strong>What is Service Broker?</strong></p>
<p style="text-align:justify;">Service Broker is a message-queuing technology in SQL Server that allows developers to integrate SQL Server fully into distributed applications. Service Broker is feature which provides facility to SQL Server to send an asynchronous, transactional message. it allows a database to send a message to another database without waiting for the response, so the application will continue to function if the remote database is temporarily unavailable. (<a href="http://blog.sqlauthority.com/2008/07/18/sql-server-introduction-to-service-broker/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>Where SQL server user names and passwords are stored in SQL server?</strong></p>
<p style="text-align:justify;">They get stored in System Catalog Views sys.server_principals and sys.sql_logins.</p>
<p style="text-align:justify;"><strong>What is Policy Management?</strong></p>
<p style="text-align:justify;">Policy Management in SQL SERVER 2008 allows you to define and enforce policies for configuring and managing SQL Server across the enterprise. Policy-Based Management is configured in SQL Server Management Studio (SSMS).  Navigate to the Object Explorer and expand the Management node and the Policy Management node; you will see the Policies, Conditions, and Facets nodes. (<a href="http://blog.sqlauthority.com/2008/06/13/sql-server-2008-introduction-to-policy-management-enforcing-rules-on-sql-server/" target="_blank">Read More Here</a>)<strong></strong></p>
<p style="text-align:justify;"><strong>What is Replication and Database Mirroring?</strong></p>
<p style="text-align:justify;">Database mirroring can be used with replication to provide availability for the publication database. Database mirroring involves two copies of a single database that typically reside on different computers. At any given time, only one copy of the database is currently available to clients which are known as the principal database. Updates made by clients to the principal database are applied on the other copy of the database, known as the mirror database. Mirroring involves applying the transaction log from every insertion, update, or deletion made on the principal database onto the mirror database.</p>
<p style="text-align:justify;"><strong>What are Sparse Columns?</strong></p>
<p style="text-align:justify;">A sparse column<em> </em>is another tool used to reduce the amount of physical storage used in a database. They are the ordinary columns that have an optimized storage for null values. Sparse columns reduce the space requirements for null values at the cost of more overhead to retrieve nonnull values. (<a href="http://blog.sqlauthority.com/2008/07/10/sql-server-2008-introduction-to-sparse-columns/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What does TOP Operator Do?</strong></p>
<p style="text-align:justify;">The TOP operator is used to specify the number of rows to be returned by a query. The TOP operator has new addition in SQL SERVER 2008 that it accepts variables as well as literal values and can be used with INSERT, UPDATE, and DELETES statements.</p>
<p style="text-align:justify;"><strong>What is CTE?</strong></p>
<p style="text-align:justify;">CTE is an abbreviation Common Table Expression. A Common Table Expression (CTE) is an expression that can be thought of as a temporary result set which is defined within the execution of a single SQL statement<strong>. </strong>A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query. (<a href="http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/" target="_blank">Read More Here</a>)</p>
<p style="text-align:justify;"><strong>What is MERGE Statement?</strong><strong><br />
</strong>MERGE is a new feature that provides an efficient way to perform multiple DML operations. In previous versions of SQL Server, we had to write separate statements to INSERT, UPDATE, or DELETE data based on certain conditions, but now, using MERGE statement we can include the logic of such data modifications in one statement that even checks when the data is matched then just update it and when unmatched then insert it. One of the most important advantages of MERGE statement is all the data is read and processed only once.  (<a href="http://blog.sqlauthority.com/2008/08/28/sql-server-2008-introduction-to-merge-statement-one-statement-for-insert-update-delete/" target="_blank">Read More Here</a>)
</p>
<p style="text-align:justify;"><strong>What is Filtered Index?</strong></p>
<p style="text-align:justify;">Filtered Index is used to index a portion of rows in a table that means it applies filter on INDEX which improves query performance, reduce index maintenance costs, and reduce index storage costs compared with full-table indexes. When we see an Index created with some where clause then that is actually a FILTERED INDEX.</p>
<p style="text-align:justify;"><strong>Which are new data types introduced in SQL SERVER 2008?</strong></p>
<p style="text-align:justify;"><strong><em>The GEOMETRY Type: </em></strong>The GEOMETRY data type is a system .NET common language runtime (CLR) data type in SQL Server. This type represents data in a two-dimensional Euclidean coordinate system.</p>
<p style="text-align:justify;"><strong><em>The GEOGRAPHY Type:</em></strong> The GEOGRAPHY datatype&#8217;s functions are the same as with GEOMETRY. The difference between the two is that when you specify GEOGRAPHY, you are usually specifying points in terms of latitude and longitude.</p>
<p style="text-align:justify;"><strong><em>New Date and Time Datatypes:</em></strong> SQL Server 2008 introduces four new datatypes related to date and time: DATE, TIME, DATETIMEOFFSET, and DATETIME2.</p>
<ul class="unIndentedList" style="text-align:justify;">
<li> <strong><em>DATE</em></strong><em>:</em> The new DATE type just stores the date itself. It is based on the Gregorian calendar and handles years from 1 to 9999.</li>
<li> <strong><em>TIME</em></strong><em>:</em> The new TIME (<em>n</em>) type stores time with a range of 00:00:00.0000000 through 23:59:59.9999999. The precision is allowed with this type. TIME supports seconds down to 100 nanoseconds. The <em>n </em>in TIME (<em>n</em>) defines this level of fractional second precision, from 0 to 7 digits of precision.</li>
</ul>
<ul class="unIndentedList" style="text-align:justify;">
<li> <strong><em>The DATETIMEOFFSET Type</em></strong>: DATETIMEOFFSET (<em>n</em>) is the time-zone-aware version of a datetime datatype. The name will appear less odd when you consider what it really is: a date + a time + a time-zone offset. The offset is based on how far behind or ahead you are from Coordinated Universal Time (UTC) time.</li>
</ul>
<ul class="unIndentedList" style="text-align:justify;">
<li> <strong><em>The DATETIME2 Type</em></strong>: It is an extension of the datetime type in earlier versions of SQL Server. This new datatype has a date range covering dates from January 1 of year 1 through December 31 of year 9999. This is a definite improvement over the 1753 lower boundary of the datetime datatype. DATETIME2 not only includes the larger date range, but also has a timestamp and the same fractional precision that TIME type provides</li>
</ul>
<p style="text-align:justify;"><strong>What are the Advantages of using CTE?</strong></p>
<ul class="unIndentedList" style="text-align:justify;">
<li> Using CTE improves the readability and makes maintenance of complex queries easy.</li>
<li> The query can be divided into separate, simple, logical building blocks which can be then used to build more complex CTEs until final result set is generated.</li>
<li> CTE can be defined in functions, stored procedures, triggers or even views.</li>
<li> After a CTE is defined, it can be used as a Table or a View and can SELECT, INSERT, UPDATE or DELETE Data.</li>
</ul>
<p style="text-align:justify;">© Copyright 2000-2009<a title="Pinal Dave" href="http://www.pinaldave.com/" target="_blank"> Pinal Dave.</a> All Rights Reserved. <a href="http://blog.sqlauthority.com/" target="_blank">SQLAuthority.com</a></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/1008/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/1008/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/1008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/1008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/1008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/1008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/1008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/1008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/1008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/1008/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/1008/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/1008/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=1008&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/09/17/sql-server-2008-interview-questions-and-answers-part-6/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Few Useful DateTime Functions to Find Specific Dates</title>
		<link>http://blog.sqlauthority.com/2008/08/29/sql-server-few-useful-datetime-functions-to-find-specific-dates/</link>
		<comments>http://blog.sqlauthority.com/2008/08/29/sql-server-few-useful-datetime-functions-to-find-specific-dates/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 01:30:00 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=916</guid>
		<description><![CDATA[Recently I have recieved email from Vivek Jamwal, which contains many useful SQL Server Date functions. 
----Today
SELECT GETDATE() 'Today'
----Yesterday
SELECT DATEADD(d,-1,GETDATE()) 'Yesterday'
----First Day of Current Week
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) 'First Day of Current Week'
----Last Day of Current Week
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6) 'Last Day of Current Week'
----First Day of Last Week
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) 'First Day of Last Week'
----Last Day of Last Week
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6) 'Last Day of Last Week'
----First Day of Current Month
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) 'First Day of Current Month'
----Last Day of Current Month
SELECT DATEADD(ms,- 3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0))) 'Last Day of Current Month'
----First Day of Last Month
SELECT DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)) 'First Day of Last Month'
----Last Day of Last Month
SELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))) 'Last Day of Last Month'
----First Day of Current Year
SELECT DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0) 'First Day of Current Year'
----Last Day of Current Year
SELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE())+1,0))) 'Last Day of Current Year'
----First Day of Last Year
SELECT DATEADD(yy,-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) 'First Day of Last Year'
----Last Day of Last Year
SELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))) 'Last Day of Last Year' 

ResultSet:
Today
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
2008-08-29 21:54:58.967
Yesterday
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
2008-08-28 21:54:58.967
First Day of Current Week
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
2008-08-25 00:00:00.000
Last Day [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=916&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Recently I have recieved email from <span class="email"><strong>Vivek Jamwal</strong>, which contains many useful SQL Server Date functions. </span></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:green;">----Today<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">() </span><span style="color:red;">'Today'<br />
</span><span style="color:green;">----Yesterday<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,-</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) </span><span style="color:red;">'Yesterday'<br />
</span><span style="color:green;">----First Day of Current Week<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:red;">'First Day of Current Week'<br />
</span><span style="color:green;">----Last Day of Current Week<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">6</span><span style="color:gray;">) </span><span style="color:red;">'Last Day of Current Week'<br />
</span><span style="color:green;">----First Day of Last Week<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:black;">7</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:red;">'First Day of Last Week'<br />
</span><span style="color:green;">----Last Day of Last Week<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">wk</span><span style="color:gray;">,</span><span style="color:black;">7</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">6</span><span style="color:gray;">) </span><span style="color:red;">'Last Day of Last Week'<br />
</span><span style="color:green;">----First Day of Current Month<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:red;">'First Day of Current Month'<br />
</span><span style="color:green;">----Last Day of Current Month<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">ms</span><span style="color:gray;">,- </span><span style="color:black;">3</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">())+</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">))) </span><span style="color:red;">'Last Day of Current Month'<br />
</span><span style="color:green;">----First Day of Last Month<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,-</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">)) </span><span style="color:red;">'First Day of Last Month'<br />
</span><span style="color:green;">----Last Day of Last Month<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">ms</span><span style="color:gray;">,-</span><span style="color:black;">3</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">mm</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">))) </span><span style="color:red;">'Last Day of Last Month'<br />
</span><span style="color:green;">----First Day of Current Year<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">) </span><span style="color:red;">'First Day of Current Year'<br />
</span><span style="color:green;">----Last Day of Current Year<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">ms</span><span style="color:gray;">,-</span><span style="color:black;">3</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">())+</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">))) </span><span style="color:red;">'Last Day of Current Year'<br />
</span><span style="color:green;">----First Day of Last Year<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,-</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">)) </span><span style="color:red;">'First Day of Last Year'<br />
</span><span style="color:green;">----Last Day of Last Year<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">ms</span><span style="color:gray;">,-</span><span style="color:black;">3</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:magenta;">DATEDIFF</span><span style="color:gray;">(</span><span style="color:black;">yy</span><span style="color:gray;">,</span><span style="color:black;">0</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()),</span><span style="color:black;">0</span><span style="color:gray;">))) </span><span style="color:red;">'Last Day of Last Year' </span></code>
</p>
<p style="text-align:justify;"><strong>ResultSet:</strong></p>
<p style="text-align:justify;">Today<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-08-29 21:54:58.967</p>
<p style="text-align:justify;">Yesterday<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-08-28 21:54:58.967</p>
<p style="text-align:justify;">First Day of Current Week<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
2008-08-25 00:00:00.000</p>
<p style="text-align:justify;">Last Day of Current Week<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
2008-08-31 00:00:00.000</p>
<p style="text-align:justify;">First Day of Last Week<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-08-18 00:00:00.000</p>
<p style="text-align:justify;">Last Day of Last Week<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-08-24 00:00:00.000</p>
<p style="text-align:justify;">First Day of Current Month<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-08-01 00:00:00.000</p>
<p style="text-align:justify;">Last Day of Current Month<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
2008-08-31 23:59:59.997</p>
<p style="text-align:justify;">First Day of Last Month<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-07-01 00:00:00.000</p>
<p style="text-align:justify;">Last Day of Last Month<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-07-31 23:59:59.997</p>
<p style="text-align:justify;">First Day of Current Year<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
2008-01-01 00:00:00.000</p>
<p style="text-align:justify;">Last Day of Current Year<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
2008-12-31 23:59:59.997</p>
<p style="text-align:justify;">First Day of Last Year<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2007-01-01 00:00:00.000</p>
<p style="text-align:justify;">Last Day of Last Year<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2007-12-31 23:59:59.997
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong>, <span class="email">Vivek Jamwal</span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/916/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/916/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/916/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/916/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/916/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=916&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/08/29/sql-server-few-useful-datetime-functions-to-find-specific-dates/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Get Date Time in Any Format &#8211; UDF &#8211; User Defined Functions</title>
		<link>http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions/</link>
		<comments>http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 01:30:13 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=820</guid>
		<description><![CDATA[One of the reader Nanda of SQLAuthority.com has posted very detailed script of converting any date time in desired format. I suggest every reader of this blog to save this script in your permanent code bookmark and use it when you need it.
Refer the function and get familiar yourself with different format this function support. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=820&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">One of the reader <a href="http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41412" target="_blank">Nanda </a>of SQLAuthority.com has posted very detailed script of converting any date time in desired format. I suggest every reader of this blog to save this script in your permanent code bookmark and use it when you need it.</p>
<p style="text-align:justify;">Refer the function and get familiar yourself with different format this function support. I have added few examples of how this function can be used at the end of the article. You can download whole code in ZIP format as well.</p>
<p style="text-align:justify;"><a href="http://www.pinaldave.com/blogfolder/anyformatudf.zip" target="_blank">Download Get Date Time in Any Format Script (ZIP)</a></p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">[dbo].[ufsFormat]<br />
</span><span style="color:gray;">(<br />
</span><span style="color:#434343;">@Date </span><span style="color:black;">datetime</span><span style="color:gray;">,<br />
</span><span style="color:#434343;">@fORMAT </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">80</span><span style="color:gray;">)<br />
)<br />
</span><span style="color:blue;">RETURNS NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">80</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@Dateformat </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@ReturnedDate </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">80</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@TwelveHourClock </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@Before </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@pos </span><span style="color:blue;">INT<br />
DECLARE </span><span style="color:#434343;">@Escape </span><span style="color:blue;">INT </span><br />
<span style="color:green;">-- (c) Pinal Dave http://www.SQLAuthority.com </span></code><br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:red;">'error! unrecognised format '</span><span style="color:gray;">+</span><span style="color:#434343;">@format<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@DateFormat</span><span style="color:blue;">=</span><span style="color:magenta;">CASE </span><span style="color:#434343;">@format<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'mmm dd yyyy hh:mm AM/PM' </span><span style="color:blue;">THEN </span><span style="color:black;">100<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'mm/dd/yy' </span><span style="color:blue;">THEN </span><span style="color:black;">1<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'mm/dd/yyyy' </span><span style="color:blue;">THEN </span><span style="color:black;">101<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yy.mm.dd' </span><span style="color:blue;">THEN </span><span style="color:black;">2<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd/mm/yy' </span><span style="color:blue;">THEN </span><span style="color:black;">3<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd.mm.yy' </span><span style="color:blue;">THEN </span><span style="color:black;">4<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd-mm-yy' </span><span style="color:blue;">THEN </span><span style="color:black;">5<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd Mmm yy' </span><span style="color:blue;">THEN </span><span style="color:black;">6<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmm dd, yy' </span><span style="color:blue;">THEN </span><span style="color:black;">7<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'hh:mm:ss' </span><span style="color:blue;">THEN </span><span style="color:black;">8<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yyyy.mm.dd' </span><span style="color:blue;">THEN </span><span style="color:black;">102<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd/mm/yyyy' </span><span style="color:blue;">THEN </span><span style="color:black;">103<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd.mm.yyyy' </span><span style="color:blue;">THEN </span><span style="color:black;">104<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd-mm-yyyy' </span><span style="color:blue;">THEN </span><span style="color:black;">105<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd Mmm yyyy' </span><span style="color:blue;">THEN </span><span style="color:black;">106<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmm dd, yyyy' </span><span style="color:blue;">THEN </span><span style="color:black;">107<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmm dd yyyy hh:mm:ss:ms AM/PM' </span><span style="color:blue;">THEN </span><span style="color:black;">9<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmm dd yyyy hh:mi:ss:mmm AM/PM' </span><span style="color:blue;">THEN </span><span style="color:black;">9<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmm dd yy hh:mm:ss:ms AM/PM' </span><span style="color:blue;">THEN </span><span style="color:black;">109<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'mm-dd-yy' </span><span style="color:blue;">THEN </span><span style="color:black;">10<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'mm-dd-yyyy' </span><span style="color:blue;">THEN </span><span style="color:black;">110<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yy/mm/dd' </span><span style="color:blue;">THEN </span><span style="color:black;">11<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yyyy/mm/dd' </span><span style="color:blue;">THEN </span><span style="color:black;">111<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yymmdd' </span><span style="color:blue;">THEN </span><span style="color:black;">12<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yyyymmdd' </span><span style="color:blue;">THEN </span><span style="color:black;">112<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd Mmm yyyy hh:mm:ss:Ms' </span><span style="color:blue;">THEN </span><span style="color:black;">113<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'hh:mm:ss:Ms' </span><span style="color:blue;">THEN </span><span style="color:black;">14<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yyyy-mm-dd hh:mm:ss' </span><span style="color:blue;">THEN </span><span style="color:black;">120<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yyyy-mm-dd hh:mm:ss.Ms' </span><span style="color:blue;">THEN </span><span style="color:black;">121<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'yyyy-mm-ddThh:mm:ss.Ms' </span><span style="color:blue;">THEN </span><span style="color:black;">126<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd Mmm yyyy hh:mm:ss:ms AM/PM' </span><span style="color:blue;">THEN </span><span style="color:black;">130<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd/mm/yy hh:mm:ss:ms AM/PM' </span><span style="color:blue;">THEN </span><span style="color:black;">131<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'RFC822' </span><span style="color:blue;">THEN </span><span style="color:black;">2<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dd Mmm yyyy hh:mm' </span><span style="color:blue;">THEN </span><span style="color:black;">4<br />
</span><span style="color:blue;">ELSE </span><span style="color:black;">1 </span><span style="color:blue;">END<br />
SELECT </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:red;">'error! unrecognised format ' </span><span style="color:gray;">+</span><span style="color:#434343;">@format</span><span style="color:gray;">+</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">),</span><span style="color:#434343;">@DateFormat</span><span style="color:gray;">)<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@DateFormat</span><span style="color:gray;">&gt;=</span><span style="color:black;">0<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">80</span><span style="color:gray;">),</span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:#434343;">@DateFormat</span><span style="color:gray;">)<br />
</span><span style="color:green;">--check for favourite and custom formats that can be done quickly<br />
</span><span style="color:blue;">ELSE IF </span><span style="color:#434343;">@DateFormat</span><span style="color:blue;">=</span><span style="color:gray;">-</span><span style="color:black;">2</span><span style="color:green;">--then it is RFC822 format<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:magenta;">LEFT</span><span style="color:gray;">(</span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">dw</span><span style="color:gray;">, </span><span style="color:#434343;">@Date</span><span style="color:gray;">),</span><span style="color:black;">3</span><span style="color:gray;">) + </span><span style="color:red;">', ' </span><span style="color:gray;">+ </span><span style="color:magenta;">STUFF</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:black;">113</span><span style="color:gray;">),</span><span style="color:black;">21</span><span style="color:gray;">,</span><span style="color:black;">4</span><span style="color:gray;">,</span><span style="color:red;">' GMT'</span><span style="color:gray;">)<br />
</span><span style="color:blue;">ELSE IF </span><span style="color:#434343;">@DateFormat</span><span style="color:blue;">=</span><span style="color:gray;">-</span><span style="color:black;">4</span><span style="color:green;">--then it is european day format with minutes<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">17</span><span style="color:gray;">),</span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:black;">113</span><span style="color:gray;">)<br />
</span><span style="color:blue;">ELSE<br />
BEGIN<br />
SELECT </span><span style="color:#434343;">@Before</span><span style="color:blue;">=</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@format</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Format</span><span style="color:blue;">=</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">( </span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:red;">'AM/PM'</span><span style="color:gray;">,</span><span style="color:red;">'#'</span><span style="color:gray;">),</span><span style="color:red;">'AM'</span><span style="color:gray;">,</span><span style="color:red;">'#'</span><span style="color:gray;">),</span><span style="color:red;">'PM'</span><span style="color:gray;">,</span><span style="color:red;">'#'</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@TwelveHourClock</span><span style="color:blue;">=</span><span style="color:magenta;">CASE </span><span style="color:blue;">WHEN </span><span style="color:#434343;">@Before </span><span style="color:gray;">&gt;</span><span style="color:magenta;">LEN</span><span style="color:gray;">(</span><span style="color:#434343;">@format</span><span style="color:gray;">) </span><span style="color:blue;">THEN </span><span style="color:black;">109 </span><span style="color:blue;">ELSE </span><span style="color:black;">113 </span><span style="color:blue;">END</span><span style="color:gray;">, </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:red;">''<br />
</span><span style="color:blue;">WHILE </span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:blue;">=</span><span style="color:black;">1</span><span style="color:gray;">)</span><span style="color:green;">--forever<br />
</span><span style="color:blue;">BEGIN<br />
SELECT </span><span style="color:#434343;">@pos</span><span style="color:blue;">=</span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[yqmidwhs:#]%'</span><span style="color:gray;">,</span><span style="color:#434343;">@format</span><span style="color:gray;">+</span><span style="color:red;">' '</span><span style="color:gray;">)<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@pos</span><span style="color:blue;">=</span><span style="color:black;">0</span><span style="color:green;">--no more date format strings<br />
</span><span style="color:blue;">BEGIN<br />
SELECT </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:#434343;">@ReturnedDate</span><span style="color:gray;">+</span><span style="color:#434343;">@format<br />
</span><span style="color:blue;">BREAK<br />
END<br />
IF </span><span style="color:#434343;">@pos</span><span style="color:gray;">&gt;</span><span style="color:black;">1</span><span style="color:green;">--some stuff to pass through first<br />
</span><span style="color:blue;">BEGIN<br />
SELECT </span><span style="color:#434343;">@escape</span><span style="color:blue;">=CHARINDEX </span><span style="color:gray;">(</span><span style="color:red;">'\'</span><span style="color:gray;">,</span><span style="color:#434343;">@Format</span><span style="color:gray;">+</span><span style="color:red;">'\'</span><span style="color:gray;">) </span><span style="color:green;">--is it a literal character that is escaped?<br />
</span><span style="color:blue;">IF </span><span style="color:#434343;">@escape</span><span style="color:gray;">&lt;</span><span style="color:#434343;">@pos </span><span style="color:blue;">BEGIN<br />
SET </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:#434343;">@ReturnedDate</span><span style="color:gray;">+</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:#434343;">@escape</span><span style="color:gray;">-</span><span style="color:black;">1</span><span style="color:gray;">) +</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@format</span><span style="color:gray;">,</span><span style="color:#434343;">@escape</span><span style="color:gray;">+</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@format</span><span style="color:blue;">=</span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:#434343;">@Escape</span><span style="color:gray;">+</span><span style="color:black;">2</span><span style="color:gray;">,</span><span style="color:black;">80</span><span style="color:gray;">))<br />
</span><span style="color:blue;">CONTINUE<br />
END<br />
SET </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:#434343;">@ReturnedDate</span><span style="color:gray;">+</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:#434343;">@pos</span><span style="color:gray;">-</span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@format</span><span style="color:blue;">=</span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:#434343;">@pos</span><span style="color:gray;">,</span><span style="color:black;">80</span><span style="color:gray;">))<br />
</span><span style="color:blue;">END<br />
SELECT </span><span style="color:#434343;">@pos</span><span style="color:blue;">=</span><span style="color:magenta;">PATINDEX</span><span style="color:gray;">(</span><span style="color:red;">'%[^yqmidwhs:#]%'</span><span style="color:gray;">,</span><span style="color:#434343;">@format</span><span style="color:gray;">+</span><span style="color:red;">' '</span><span style="color:gray;">)</span><span style="color:green;">--get the end<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@ReturnedDate</span><span style="color:blue;">=</span><span style="color:#434343;">@ReturnedDate</span><span style="color:gray;">+</span><span style="color:green;">--'('+substring(@Format,1,@pos-1)+')'+<br />
</span><span style="color:magenta;">CASE SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:#434343;">@pos</span><span style="color:gray;">-</span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Mmmths as 1--12<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'M' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:magenta;">MONTH</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">))<br />
</span><span style="color:green;">--Mmmths as 01--12<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mm' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:black;">101</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Mmmths as Jan--Dec<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmm' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">3</span><span style="color:gray;">),</span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:magenta;">MONTH</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">))<br />
</span><span style="color:green;">--Mmmths as January--December<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmmm' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:magenta;">MONTH</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Mmmths as the first letter of the Mmmth<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mmmmm' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">),</span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:magenta;">MONTH</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">))<br />
</span><span style="color:green;">--Days as 1--31<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'D' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:magenta;">DAY</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">))<br />
</span><span style="color:green;">--Days as 01--31<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Dd' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:#434343;">@date</span><span style="color:gray;">,</span><span style="color:black;">103</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Days as Sun--Sat<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Ddd' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">3</span><span style="color:gray;">),</span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">weekday</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">))<br />
</span><span style="color:green;">--Days as Sunday--Saturday<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Dddd' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">weekday</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Years as 00--99<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Yy' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:black;">12</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Years as 1900--9999<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Yyyy' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:magenta;">YEAR</span><span style="color:gray;">,</span><span style="color:#434343;">@Date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'hh:mm:ss' </span><span style="color:blue;">THEN </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">),</span><span style="color:#434343;">@date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">8</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'hh:mm:ss:ms' </span><span style="color:blue;">THEN </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">),</span><span style="color:#434343;">@date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">12</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'h:mm:ss' </span><span style="color:blue;">THEN </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">),</span><span style="color:#434343;">@date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">8</span><span style="color:gray;">)<br />
</span><span style="color:green;">--tthe SQL Server BOL syntax, for compatibility<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'hh:mi:ss:mmm' </span><span style="color:blue;">THEN </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">),</span><span style="color:#434343;">@date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">12</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'h:mm:ss:ms' </span><span style="color:blue;">THEN </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">),</span><span style="color:#434343;">@date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">12</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'H:m:s' </span><span style="color:blue;">THEN </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:red;">':'</span><span style="color:gray;">+</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">), </span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">8</span><span style="color:gray;">),</span><span style="color:red;">':0'</span><span style="color:gray;">,</span><span style="color:red;">':'</span><span style="color:gray;">),</span><span style="color:black;">2</span><span style="color:gray;">,</span><span style="color:black;">30</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'H:m:s:ms' </span><span style="color:blue;">THEN </span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:red;">':'</span><span style="color:gray;">+</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">), </span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">12</span><span style="color:gray;">),</span><span style="color:red;">':0'</span><span style="color:gray;">,</span><span style="color:red;">':'</span><span style="color:gray;">),</span><span style="color:black;">2</span><span style="color:gray;">,</span><span style="color:black;">30</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Hours as 00--23<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'hh' </span><span style="color:blue;">THEN </span><span style="color:magenta;">REPLACE</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">), </span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:red;">' '</span><span style="color:gray;">,</span><span style="color:red;">'0'</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Hours as 0--23<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'h' </span><span style="color:blue;">THEN </span><span style="color:magenta;">LTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">30</span><span style="color:gray;">), </span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:#434343;">@TwelveHourClock</span><span style="color:gray;">),</span><span style="color:black;">13</span><span style="color:gray;">,</span><span style="color:black;">2</span><span style="color:gray;">))<br />
</span><span style="color:green;">--Minutes as 00--59<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'Mi' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">minute</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'mm' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">minute</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'m' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">minute</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">))<br />
</span><span style="color:green;">--Seconds as 0--59<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'ss' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">second</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:green;">--Seconds as 0--59<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'S' </span><span style="color:blue;">THEN </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">2</span><span style="color:gray;">),</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">second</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">))<br />
</span><span style="color:green;">--AM/PM<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'ms' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">millisecond</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'mmm' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">millisecond</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'dy' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">dy</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'qq' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">qq</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'ww' </span><span style="color:blue;">THEN </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">ww</span><span style="color:gray;">,</span><span style="color:#434343;">@date</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:red;">'#' </span><span style="color:blue;">THEN </span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:magenta;">REVERSE</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">CHAR</span><span style="color:gray;">(</span><span style="color:black;">26</span><span style="color:gray;">), </span><span style="color:#434343;">@date</span><span style="color:gray;">,</span><span style="color:black;">109</span><span style="color:gray;">)),</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:black;">2</span><span style="color:gray;">))<br />
</span><span style="color:blue;">ELSE<br />
</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:black;">1</span><span style="color:gray;">,</span><span style="color:#434343;">@pos</span><span style="color:gray;">-</span><span style="color:black;">1</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
SET </span><span style="color:#434343;">@format</span><span style="color:blue;">=</span><span style="color:magenta;">RTRIM</span><span style="color:gray;">(</span><span style="color:magenta;">SUBSTRING</span><span style="color:gray;">(</span><span style="color:#434343;">@Format</span><span style="color:gray;">,</span><span style="color:#434343;">@pos</span><span style="color:gray;">,</span><span style="color:black;">80</span><span style="color:gray;">))<br />
</span><span style="color:blue;">END<br />
END<br />
RETURN </span><span style="color:#434343;">@ReturnedDate<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">[dbo].[ufsFormat] </span><span style="color:gray;">(</span><span style="color:red;">'8/7/2008'</span><span style="color:gray;">, </span><span style="color:red;">'mm/dd/yy'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">[dbo].[ufsFormat] </span><span style="color:gray;">(</span><span style="color:red;">'8/7/2008'</span><span style="color:gray;">, </span><span style="color:red;">'hh:mm:ss'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">[dbo].[ufsFormat] </span><span style="color:gray;">(</span><span style="color:red;">'8/7/2008'</span><span style="color:gray;">, </span><span style="color:red;">'mmm'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">[dbo].[ufsFormat] </span><span style="color:gray;">(</span><span style="color:red;">'8/7/2008'</span><span style="color:gray;">, </span><span style="color:red;">'Mmm dd yyyy hh:mm:ss:ms AM/PM'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">[dbo].[ufsFormat] </span><span style="color:gray;">(</span><span style="color:red;">'8/7/2008'</span><span style="color:gray;">, </span><span style="color:red;">'#'</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/dateudf.jpg" alt="" width="500" height="407" /></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong> , <a href="http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comment-41412" target="_blank">Nanda</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/820/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/820/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/820/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/820/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/820/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/820/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/820/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/820/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/820/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/820/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/820/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/820/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=820&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/08/14/sql-server-get-date-time-in-any-format-udf-user-defined-functions/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/dateudf.jpg" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Get Current System Date Time</title>
		<link>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/</link>
		<comments>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 01:30:06 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=764</guid>
		<description><![CDATA[How to get current system date time in SQL Server?
First thing which comes to many users is using following script.
SELECT GETDATE() AS CurrentDateTime
Above method is not the only method to retrieve the current system date time for SQL Server. SQL Server 2008 has many different function which provides current system date time in different format [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=764&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">How to get current system date time in SQL Server?</p>
<p style="text-align:justify;">First thing which comes to many users is using following script.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">() </span><span style="color:blue;">AS </span><span style="color:black;">CurrentDateTime</span></code></p>
<p style="text-align:justify;">Above method is not the only method to retrieve the current system date time for SQL Server. SQL Server 2008 has many different function which provides current system date time in different format and little difference in details.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:red;">'SYSDATETIME' </span><span style="color:blue;">AS </span><span style="color:black;">FunctionName</span><span style="color:gray;">, </span><span style="color:black;">SYSDATETIME</span><span style="color:gray;">() </span><span style="color:blue;">AS </span><span style="color:black;">DateTimeFormat<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'SYSDATETIMEOFFSET'</span><span style="color:gray;">, </span><span style="color:black;">SYSDATETIMEOFFSET</span><span style="color:gray;">()<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'SYSUTCDATETIME'</span><span style="color:gray;">, </span><span style="color:black;">SYSUTCDATETIME</span><span style="color:gray;">()<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'CURRENT_TIMESTAMP'</span><span style="color:gray;">, </span><span style="color:magenta;">CURRENT_TIMESTAMP<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'GETDATE'</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:red;">'GETUTCDATE'</span><span style="color:gray;">, </span><span style="color:magenta;">GETUTCDATE</span><span style="color:gray;">() </span></code>
</p>
<p style="text-align:justify;">In SQL Server 2008, use any of the above function depending on your need.</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/datetime2008.gif" alt="" width="422" height="406" /></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/764/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/764/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/764/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/764/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/764/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=764&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/datetime2008.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; Find Current System Date Time and Time Offset</title>
		<link>http://blog.sqlauthority.com/2008/07/31/sql-server-2008-find-current-system-date-time-and-time-offset/</link>
		<comments>http://blog.sqlauthority.com/2008/07/31/sql-server-2008-find-current-system-date-time-and-time-offset/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 01:30:23 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=756</guid>
		<description><![CDATA[If you want to find current datetime in SQL Server I suggest to read the following post :
SQL SERVER &#8211; Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}
This post is related to new feature available in SQL Server 2008. In SQL Server 2008 there is a function which provides current offset of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=756&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">If you want to find current datetime in SQL Server I suggest to read the following post :</p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/21/sql-server-retrieve-current-date-time-in-sql-server-current_timestamp-getdate-fn-now/" target="_blank">SQL SERVER &#8211; Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}</a></p>
<p style="text-align:justify;">This post is related to new feature available in SQL Server 2008. In SQL Server 2008 there is a function which provides current offset of the system from GMT time as well. Basically it shows the system datetime with offset. I think this can be useful in some of the instances where SQL Server are depending on the time offset.</p>
<p style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">SYSDATETIMEOFFSET</span><span style="color:gray;">() </span><span style="color:blue;">AS </span><span style="color:red;">'Windows System Time'<br />
</span><span style="color:black;">GO</span></code>
</p>
<p style="text-align:justify;"><img class="alignnone" src="http://www.pinaldave.com/blogfolder/timeoffset.gif" alt="" width="461" height="522" /></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/756/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/756/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/756/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/756/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/756/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/756/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/756/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/756/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/756/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/756/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/756/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/756/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=756&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/07/31/sql-server-2008-find-current-system-date-time-and-time-offset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/timeoffset.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; SQL Server Start Time</title>
		<link>http://blog.sqlauthority.com/2008/06/17/sql-server-2008-sql-server-start-time/</link>
		<comments>http://blog.sqlauthority.com/2008/06/17/sql-server-2008-sql-server-start-time/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 01:30:29 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=650</guid>
		<description><![CDATA[I have been playing with SQL Server 2008 recently. There are many new features which SQL Server 2008 have. One of the interesting addition to SQL Server 2008 is system table field which records when SQL Server was started. This field has data type as datetime that is why it is precise to 3 milisecond.
Note [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=650&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have been playing with SQL Server 2008 recently. There are many new features which SQL Server 2008 have. One of the interesting addition to SQL Server 2008 is system table field which records when SQL Server was started. This field has data type as datetime that is why it is precise to 3 milisecond.</p>
<p style="text-align:justify;">Note : This will not work with SQL Server 2005 or earlier version. This works with SQL Server 2008 only.</p>
<p><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">sqlserver_start_time<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">sys.dm_os_sys_info</span></code></p>
<p style="text-align:justify;"><strong>ResultSet:</strong><br />
sqlserver_start_time<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-06-27 20:51:53.317</p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/650/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/650/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/650/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/650/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=650&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/06/17/sql-server-2008-sql-server-start-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function &#8211; Part 4</title>
		<link>http://blog.sqlauthority.com/2008/06/01/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-4/</link>
		<comments>http://blog.sqlauthority.com/2008/06/01/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-4/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 01:30:38 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=623</guid>
		<description><![CDATA[I have been asked many times when there is DATENAME function available why do I go in exercise of writing UDF For the getting the day of the week. Answer is : I just like it!
SELECT DATENAME(dw, GETDATE())
Reference : Pinal Dave (http://blog.SQLAuthority.com)
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=623&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have been asked many times when there is DATENAME function available why do I go in exercise of writing UDF For the getting the day of the week. Answer is : I just like it!</p>
<pre style="text-align:justify;"><code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">DATENAME</span><span style="color:gray;">(</span><span style="color:black;">dw</span><span style="color:gray;">, </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">())</span></code></pre>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/623/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/623/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/623/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/623/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/623/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=623&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/06/01/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function &#8211; Part 3</title>
		<link>http://blog.sqlauthority.com/2008/05/27/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-3/</link>
		<comments>http://blog.sqlauthority.com/2008/05/27/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-3/#comments</comments>
		<pubDate>Tue, 27 May 2008 01:30:48 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=618</guid>
		<description><![CDATA[Datetime functions and stored procedures always interests me. Nanda Kumar has suggested modification to previous written article about SQL SERVER &#8211; SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function &#8211; Part 2. He has improved on UDF.
CREATE FUNCTION dbo.udf_DayOfWeek(@dtDate DATETIME)
RETURNS VARCHAR(10)
AS
BEGIN
DECLARE @rtDayofWeek VARCHAR(10)
DECLARE @weekDay INT
----Here I have subtracted 7 For keeping [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=618&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Datetime functions and stored procedures always interests me. <a href="http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-39088" target="_blank">Nanda Kumar</a> has suggested modification to previous written article about <strong><a href="http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/" target="_blank">SQL SERVER &#8211; SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function &#8211; Part 2</a></strong>. He has improved on UDF.</p>
<p><code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.udf_DayOfWeek</span><span style="color:gray;">(</span><span style="color:#434343;">@dtDate </span><span style="color:black;">DATETIME</span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@rtDayofWeek </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@weekDay </span><span style="color:blue;">INT<br />
</span><span style="color:green;">----Here I have subtracted 7 For keeping Sunday as the First day like wise for Monday we need to subtract 2 and so on<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@weekDay</span><span style="color:blue;">=</span><span style="color:gray;">((</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">dw</span><span style="color:gray;">,</span><span style="color:#434343;">@dtDate</span><span style="color:gray;">)+</span><span style="color:#434343;">@@DATEFIRST</span><span style="color:gray;">-</span><span style="color:black;">7</span><span style="color:gray;">)%</span><span style="color:black;">7</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@rtDayofWeek </span><span style="color:blue;">= </span><span style="color:magenta;">CASE </span><span style="color:#434343;">@weekDay<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'Sunday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">2 </span><span style="color:blue;">THEN </span><span style="color:red;">'Monday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">3 </span><span style="color:blue;">THEN </span><span style="color:red;">'Tuesday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">4 </span><span style="color:blue;">THEN </span><span style="color:red;">'Wednesday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">5 </span><span style="color:blue;">THEN </span><span style="color:red;">'Thursday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">6 </span><span style="color:blue;">THEN </span><span style="color:red;">'Friday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">0 </span><span style="color:blue;">THEN </span><span style="color:red;">'Saturday'<br />
</span><span style="color:blue;">END<br />
RETURN </span><span style="color:gray;">(</span><span style="color:#434343;">@rtDayofWeek</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_dayofweek</span><span style="color:gray;">(</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">())</span></code></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong> , <a href="http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-39088" target="_blank">Nanda Kumar</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/618/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/618/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/618/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/618/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/618/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/618/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/618/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/618/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/618/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/618/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/618/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/618/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=618&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/05/27/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function &#8211; Part 2</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/</link>
		<comments>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comments</comments>
		<pubDate>Fri, 23 May 2008 01:30:51 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613</guid>
		<description><![CDATA[I have written article about  SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function. I have received good modified script from reader Mihir Popat has suggested another code where Sunday does not have to be necessary the first day of the week.

CREATE FUNCTION dbo.udf_DayOfWeek(@dtDate DATETIME)
RETURNS VARCHAR(10)
AS
BEGIN
DECLARE @rtDayofWeek VARCHAR(10)
DECLARE @weekDay INT
-- Here [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=613&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">I have written article about  <strong><a href="http://blog.sqlauthority.com/2007/07/23/sql-server-udf-get-the-day-of-the-week-function/" target="_blank">SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function</a></strong>. I have received good modified script from reader <a href="http://blog.sqlauthority.com/2007/07/23/sql-server-udf-get-the-day-of-the-week-function/#comment-38946" target="_blank">Mihir Popat</a> has suggested another code where Sunday does not have to be necessary the first day of the week.<br />
<code style="font-size:12px;"><span style="color:blue;"><br />
CREATE FUNCTION </span><span style="color:black;">dbo.udf_DayOfWeek</span><span style="color:gray;">(</span><span style="color:#434343;">@dtDate </span><span style="color:black;">DATETIME</span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURNS VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@rtDayofWeek </span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@weekDay </span><span style="color:blue;">INT<br />
</span><span style="color:green;">-- Here I have subtracted 7 For keeping Sunday as the First day<br />
-- like wise for Monday we need to subtract 2 and so on<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@weekDay </span><span style="color:blue;">= </span><span style="color:gray;">((</span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">dw</span><span style="color:gray;">,</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">())+</span><span style="color:#434343;">@@DATEFIRST</span><span style="color:gray;">-</span><span style="color:black;">7</span><span style="color:gray;">)%</span><span style="color:black;">7</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@rtDayofWeek </span><span style="color:blue;">= </span><span style="color:magenta;">CASE </span><span style="color:#434343;">@weekDay<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">1 </span><span style="color:blue;">THEN </span><span style="color:red;">'Sunday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">2 </span><span style="color:blue;">THEN </span><span style="color:red;">'Monday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">3 </span><span style="color:blue;">THEN </span><span style="color:red;">'Tuesday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">4 </span><span style="color:blue;">THEN </span><span style="color:red;">'Wednesday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">5 </span><span style="color:blue;">THEN </span><span style="color:red;">'Thursday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">6 </span><span style="color:blue;">THEN </span><span style="color:red;">'Friday'<br />
</span><span style="color:blue;">WHEN </span><span style="color:black;">7 </span><span style="color:blue;">THEN </span><span style="color:red;">'Saturday'<br />
</span><span style="color:blue;">END<br />
RETURN </span><span style="color:gray;">(</span><span style="color:#434343;">@rtDayofWeek</span><span style="color:gray;">)<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_DayOfWeek</span><span style="color:gray;">(</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">())</span></code></p>
<p>Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong>, <a href="http://blog.sqlauthority.com/2007/07/23/sql-server-udf-get-the-day-of-the-week-function/#comment-38946" target="_blank">Mihir Popat</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/613/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/613/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/613/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/613/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/613/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=613&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; UDF to Return a Calendar for Any Date for Any Year</title>
		<link>http://blog.sqlauthority.com/2008/02/20/sql-server-udf-to-return-a-calendar-for-any-date-for-any-year/</link>
		<comments>http://blog.sqlauthority.com/2008/02/20/sql-server-udf-to-return-a-calendar-for-any-date-for-any-year/#comments</comments>
		<pubDate>Wed, 20 Feb 2008 01:30:32 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=512</guid>
		<description><![CDATA[It gives me great pleasure to write articles like today&#8217;s one because I have received great comment from one of regular reader who has taken UDF written by me and created another UDF using that UDF which enhances functionality of it. I had written previous article about SQL SERVER &#8211; UDF &#8211; Function to Display [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=512&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">It gives me great pleasure to write articles like today&#8217;s one because I have received great comment from one of regular reader who has taken UDF written by me and created another UDF using that UDF which enhances functionality of it. I had written previous article about <a href="http://blog.sqlauthority.com/2007/06/08/sql-server-udf-function-to-display-current-week-date-and-day-weekly-calendar/" target="_blank">SQL SERVER &#8211; UDF &#8211; Function to Display Current Week Date and Day &#8211; Weekly Calendar</a>. Reader of this blog and great SQL expert Dan Golden has wrote another UDF which uses UDF written by me. I thank Dan Golden for <a href="http://blog.sqlauthority.com/2007/06/08/sql-server-udf-function-to-display-current-week-date-and-day-weekly-calendar/#comment-33859" target="_blank">his contribution</a> to this blog. I have modified his function a bit to remove error when it was missing displaying first or last week in few cases, however I will give full credit to him for his thought.</p>
<p style="text-align:justify;">I also encourage my other readers to submit their articles to me, if I think your article will benefit other readers I will publish it here with your name. Do not send me article if it is not written by you.</p>
<p style="text-align:justify;"><strong>Step 1 : Create UDF to display current week date and day &#8211; Weekly Calender.</strong><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.DisplayCurrentWeekDays<br />
</span><span style="color:gray;">(</span><span style="color:#434343;">@today </span><span style="color:black;">SMALLDATETIME</span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURNS </span><span style="color:#434343;">@WeekDateDay </span><span style="color:blue;">TABLE<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">Sunday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Monday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Tuesday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Wednesday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Thursday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Friday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Saturday SMALLDATETIME<br />
</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
</span><span style="color:green;">/*<br />
Purpose: To return the weekly calendar for the week any date<br />
By: Pinal Dave -- SQLAuthority.com<br />
On: 6/8/2007<br />
*/<br />
</span><span style="color:blue;">BEGIN<br />
DECLARE </span><span style="color:#434343;">@day </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@today </span><span style="color:blue;">= </span><span style="color:magenta;">CAST</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">), </span><span style="color:#434343;">@today</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:black;">SMALLDATETIME</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@day </span><span style="color:blue;">= </span><span style="color:magenta;">DATEPART</span><span style="color:gray;">(</span><span style="color:black;">dw</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">)<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">@WeekDateDay </span><span style="color:gray;">(</span><span style="color:black;">Sunday</span><span style="color:gray;">, </span><span style="color:black;">Monday</span><span style="color:gray;">,<br />
</span><span style="color:black;">Tuesday</span><span style="color:gray;">, </span><span style="color:black;">Wednesday</span><span style="color:gray;">, </span><span style="color:black;">Thursday</span><span style="color:gray;">, </span><span style="color:black;">Friday</span><span style="color:gray;">, </span><span style="color:black;">Saturday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">dd</span><span style="color:gray;">, </span><span style="color:black;">1 </span><span style="color:gray;">- </span><span style="color:#434343;">@day</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">) </span><span style="color:black;">Sunday</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">dd</span><span style="color:gray;">, </span><span style="color:black;">2 </span><span style="color:gray;">- </span><span style="color:#434343;">@day</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">) </span><span style="color:black;">Monday</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">dd</span><span style="color:gray;">, </span><span style="color:black;">3 </span><span style="color:gray;">- </span><span style="color:#434343;">@day</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">) </span><span style="color:black;">Tuesday</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">dd</span><span style="color:gray;">, </span><span style="color:black;">4 </span><span style="color:gray;">- </span><span style="color:#434343;">@day</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">) </span><span style="color:black;">Wednesday</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">dd</span><span style="color:gray;">, </span><span style="color:black;">5 </span><span style="color:gray;">- </span><span style="color:#434343;">@day</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">) </span><span style="color:black;">Thursday</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">dd</span><span style="color:gray;">, </span><span style="color:black;">6 </span><span style="color:gray;">- </span><span style="color:#434343;">@day</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">) </span><span style="color:black;">Friday</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">dd</span><span style="color:gray;">, </span><span style="color:black;">7 </span><span style="color:gray;">- </span><span style="color:#434343;">@day</span><span style="color:gray;">, </span><span style="color:#434343;">@today</span><span style="color:gray;">) </span><span style="color:black;">Saturday<br />
</span><span style="color:blue;">RETURN<br />
END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<strong>Step 2 :  Create UDF to display current month date and day &#8211; Monthly Calender</strong><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">dbo.GetSQLcalendar</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate </span><span style="color:black;">SMALLDATETIME</span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURNS </span><span style="color:#434343;">@WeekDateDay </span><span style="color:blue;">TABLE<br />
</span><span style="color:gray;">(<br />
</span><span style="color:black;">Sunday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Monday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Tuesday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Wednesday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Thursday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Friday SMALLDATETIME</span><span style="color:gray;">,<br />
</span><span style="color:black;">Saturday SMALLDATETIME<br />
</span><span style="color:gray;">)<br />
</span><span style="color:blue;">AS<br />
BEGIN<br />
</span><span style="color:green;">/*<br />
Purpose: To return a calendar fOR whatever MONTH you want,<br />
driven by the date you pick AS a variable.<br />
By: Dan Golden<br />
On: 2/20/2008<br />
*/<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@FourWeeksAgo </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@FourWeeksAgo </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,-</span><span style="color:black;">28</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@ThreeWeeksAgo </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@ThreeWeeksAgo </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,-</span><span style="color:black;">21</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@TwoWeeksAgo </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@TwoWeeksAgo </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,-</span><span style="color:black;">14</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@PreviousWeek </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@PreviousWeek </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,-</span><span style="color:black;">7</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@ThisWeek </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@ThisWeek </span><span style="color:blue;">= </span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@NextWeek </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@NextWeek </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,</span><span style="color:black;">7</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@LastWeek </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@LastWeek </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,</span><span style="color:black;">14</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@AfterLastWeek </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@AfterLastWeek </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,</span><span style="color:black;">21</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@TwoAfterLastWeek </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@TwoAfterLastWeek </span><span style="color:blue;">= </span><span style="color:magenta;">DATEADD</span><span style="color:gray;">(</span><span style="color:black;">d</span><span style="color:gray;">,</span><span style="color:black;">28</span><span style="color:gray;">,</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">@WeekDateDay </span><span style="color:gray;">(</span><span style="color:black;">Sunday</span><span style="color:gray;">, </span><span style="color:black;">Monday</span><span style="color:gray;">, </span><span style="color:black;">Tuesday</span><span style="color:gray;">,<br />
</span><span style="color:black;">Wednesday</span><span style="color:gray;">, </span><span style="color:black;">Thursday</span><span style="color:gray;">, </span><span style="color:black;">Friday</span><span style="color:gray;">, </span><span style="color:black;">Saturday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">CASE MONTH</span><span style="color:gray;">(</span><span style="color:black;">calendar.Sunday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">calendar.Sunday<br />
</span><span style="color:blue;">ELSE </span><span style="color:gray;">NULL </span><span style="color:blue;">END AS </span><span style="color:red;">'Sunday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE MONTH</span><span style="color:gray;">(</span><span style="color:black;">calendar.Monday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">calendar.Monday<br />
</span><span style="color:blue;">ELSE </span><span style="color:gray;">NULL </span><span style="color:blue;">END AS </span><span style="color:red;">'Monday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE MONTH</span><span style="color:gray;">(</span><span style="color:black;">calendar.Tuesday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">calendar.Tuesday<br />
</span><span style="color:blue;">ELSE </span><span style="color:gray;">NULL </span><span style="color:blue;">END AS </span><span style="color:red;">'Tuesday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE MONTH</span><span style="color:gray;">(</span><span style="color:black;">calendar.Wednesday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">calendar.Wednesday<br />
</span><span style="color:blue;">ELSE </span><span style="color:gray;">NULL </span><span style="color:blue;">END AS </span><span style="color:red;">'Wednesday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE MONTH</span><span style="color:gray;">(</span><span style="color:black;">calendar.Thursday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">calendar.Thursday<br />
</span><span style="color:blue;">ELSE </span><span style="color:gray;">NULL </span><span style="color:blue;">END AS </span><span style="color:red;">'Thursday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE MONTH</span><span style="color:gray;">(</span><span style="color:black;">calendar.Friday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">calendar.Friday<br />
</span><span style="color:blue;">ELSE </span><span style="color:gray;">NULL </span><span style="color:blue;">END AS </span><span style="color:red;">'Friday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">CASE MONTH</span><span style="color:gray;">(</span><span style="color:black;">calendar.Saturday</span><span style="color:gray;">)<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDate</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">calendar.Saturday<br />
</span><span style="color:blue;">ELSE </span><span style="color:gray;">NULL </span><span style="color:blue;">END AS </span><span style="color:red;">'Saturday'<br />
</span><span style="color:blue;">FROM<br />
</span><span style="color:gray;">(<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@FourWeeksAgo</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@ThreeWeeksAgo</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@TwoWeeksAgo</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@PreviousWeek</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@ThisWeek</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@NextWeek</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@LastWeek</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@AfterLastWeek</span><span style="color:gray;">)<br />
</span><span style="color:blue;">UNION </span><span style="color:gray;">ALL<br />
</span><span style="color:blue;">SELECT </span><span style="color:gray;">*<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.DisplayCurrentWeekDays</span><span style="color:gray;">(</span><span style="color:#434343;">@TwoAfterLastWeek</span><span style="color:gray;">)<br />
) </span><span style="color:black;">calendar<br />
</span><span style="color:gray;">) </span><span style="color:black;">dates<br />
</span><span style="color:blue;">WHERE </span><span style="color:black;">dates.sunday </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL<br />
OR </span><span style="color:black;">dates.monday </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL<br />
OR </span><span style="color:black;">dates.tuesday </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL<br />
OR </span><span style="color:black;">dates.wednesday </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL<br />
OR </span><span style="color:black;">dates.thursday </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL<br />
OR </span><span style="color:black;">dates.friday </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL<br />
OR </span><span style="color:black;">dates.saturday </span><span style="color:blue;">IS </span><span style="color:gray;">NOT NULL<br />
</span><span style="color:blue;">RETURN<br />
END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
<strong>Step 3 : Use  recently created UDF to  get the current month &#8217;s calender. You can pass any date to this calender and it will return that month and years calender.</strong><br />
<code style="font-size:12px;"><span style="color:blue;">USE </span><span style="color:black;">AdventureWorks</span><span style="color:gray;">;<br />
</span><span style="color:black;">GO<br />
</span><span style="color:blue;">DECLARE </span><span style="color:#434343;">@WhatDay </span><span style="color:black;">SMALLDATETIME<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@WhatDay </span><span style="color:blue;">= </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">(); </span><span style="color:green;">-- you can also put here any date like 07/01/1990<br />
</span><span style="color:blue;">SELECT </span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">20</span><span style="color:gray;">), </span><span style="color:black;">Sunday</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">), </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'Sunday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">20</span><span style="color:gray;">), </span><span style="color:black;">Monday</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">), </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'Monday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">20</span><span style="color:gray;">), </span><span style="color:black;">Tuesday</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">), </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'Tuesday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">20</span><span style="color:gray;">), </span><span style="color:black;">Wednesday</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">), </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'Wednesday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">20</span><span style="color:gray;">), </span><span style="color:black;">Thursday</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">), </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'Thursday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">20</span><span style="color:gray;">), </span><span style="color:black;">Friday</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">), </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'Friday'</span><span style="color:gray;">,<br />
</span><span style="color:magenta;">ISNULL</span><span style="color:gray;">(</span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">NVARCHAR</span><span style="color:gray;">(</span><span style="color:black;">20</span><span style="color:gray;">), </span><span style="color:black;">Saturday</span><span style="color:gray;">, </span><span style="color:black;">101</span><span style="color:gray;">), </span><span style="color:red;">''</span><span style="color:gray;">) </span><span style="color:blue;">AS </span><span style="color:red;">'Saturday'<br />
</span><span style="color:blue;">FROM </span><span style="color:black;">dbo.GetSQLcalendar</span><span style="color:gray;">(</span><span style="color:#434343;">@WhatDay</span><span style="color:gray;">)<br />
</span><span style="color:black;">GO<br />
</span></code><br />
Above query will return you monthly calender for date passed to function.
</p>
<p style="text-align:justify;"><img src="http://www.pinaldave.com/blogfolder/calendar.gif" alt="" width="500" height="323" /></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong> , <a href="http://blog.sqlauthority.com/2007/06/08/sql-server-udf-function-to-display-current-week-date-and-day-weekly-calendar/#comment-33859" target="_blank">Dan Golden</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/512/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/512/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/512/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=512&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/02/20/sql-server-udf-to-return-a-calendar-for-any-date-for-any-year/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>

		<media:content url="http://www.pinaldave.com/blogfolder/calendar.gif" medium="image" />
	</item>
		<item>
		<title>SQL SERVER &#8211; Execute Same Query and Statement Multiple Times Using Command GO</title>
		<link>http://blog.sqlauthority.com/2008/01/09/sql-server-execute-same-query-and-statement-multiple-times-using-command-go/</link>
		<comments>http://blog.sqlauthority.com/2008/01/09/sql-server-execute-same-query-and-statement-multiple-times-using-command-go/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 01:30:44 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2008/01/09/sql-server-execute-same-query-and-statement-multiple-times-using-command-go/</guid>
		<description><![CDATA[Following question was asking by one of long time reader who really liked trick of SQL SERVER &#8211; Explanation SQL Command GO and SQL SERVER &#8211; Insert Multiple Records Using One Insert Statement &#8211; Use of UNION ALL. She asked how can I execute same code multiple times without Copy and Paste multiple times in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=469&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Following question was asking by one of long time reader who really liked trick of <strong><a href="http://blog.sqlauthority.com/2007/05/11/sql-server-explanation-sql-command-go/" target="_blank">SQL SERVER &#8211; Explanation SQL Command GO</a></strong> and <strong><a href="http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/" target="_blank">SQL SERVER &#8211; Insert Multiple Records Using One Insert Statement &#8211; Use of UNION ALL</a></strong>. She asked how can I execute same code multiple times without Copy and Paste multiple times in Query Editor. The answer to this question is very simple. Use the command GO. Following example demonstrate how GO can be used to execute same code multiple times.<br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">() </span><span style="color:blue;">AS </span><span style="color:black;">CurrentTime<br />
GO 5</span></code><br />
Above code will return current time 5 times as GO is followed with five times. The result is displayed with &#8220;Result to Text&#8221; mode on.<br />
Beginning execution loop<br />
CurrentTime<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-01-19 1:52:54.200
</p>
<p style="text-align:justify;">(1 row(s) affected)</p>
<p style="text-align:justify;">CurrentTime<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-01-19 11:52:54.217
</p>
<p style="text-align:justify;">(1 row(s) affected)</p>
<p style="text-align:justify;">CurrentTime<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-01-19 11:52:54.217
</p>
<p style="text-align:justify;">(1 row(s) affected)</p>
<p style="text-align:justify;">CurrentTime<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-01-19 11:52:54.217
</p>
<p style="text-align:justify;">(1 row(s) affected)</p>
<p style="text-align:justify;">CurrentTime<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2008-01-19 11:52:54.233</p>
<p style="text-align:justify;">(1 row(s) affected)<br />
Batch execution completed 5 times.
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/469/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/469/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/469/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/469/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=469&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2008/01/09/sql-server-execute-same-query-and-statement-multiple-times-using-command-go/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; 2008 &#8211; New DataTypes DATE and TIME</title>
		<link>http://blog.sqlauthority.com/2007/12/23/sql-server-2008-new-datatypes-date-and-time/</link>
		<comments>http://blog.sqlauthority.com/2007/12/23/sql-server-2008-new-datatypes-date-and-time/#comments</comments>
		<pubDate>Sun, 23 Dec 2007 01:30:31 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/12/23/sql-server-2008-new-datatypes-date-and-time/</guid>
		<description><![CDATA[One of our project manager asked me why SQL Server does not have only DATE or TIME datatypes? I thought his question is very valid, he is not DBA however he understands the RDBMS concepts very well. I find his question very interesting. I told him that there are ways to do that in SQL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=448&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">One of our project manager asked me <em><strong>why SQL Server does not have only DATE or TIME datatypes?</strong></em> I thought his question is very valid, he is not DBA however he understands the RDBMS concepts very well. I find his question very interesting. I told him that there are ways to do that in SQL Server 2005 and earlier versions.  He asked me but if there are DATE and TIME datatypes not DATETIME combined.</p>
<p style="text-align:justify;">This question we all DBA had for many years and we all wanted DATE and TIME separate datatypes then DATETIME combined. Microsoft has incorporated this feature in SQL Server 2008. It supports many new DATETIME datatypes. Today we will see DATE and TIME specifically.</p>
<p style="text-align:justify;"><strong>DATE datatype Explanation</strong></p>
<p style="text-align:justify;"><em>SQL SERVER 2005:</em><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Date </span><span style="color:blue;">AS </span><span style="color:black;">DATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Date </span><span style="color:blue;">= </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Date </span><span style="color:black;">OriginalDate</span><span style="color:gray;">, </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">),</span><span style="color:#434343;">@Date</span><span style="color:gray;">,</span><span style="color:black;">111</span><span style="color:gray;">) </span><span style="color:black;">CastDate</span></code></p>
<p style="text-align:justify;">ResultSet:<br />
OriginalDate            CastDate<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<br />
2007-12-22 17:48:14.640 2007/12/22</p>
<p style="text-align:justify;"><em>SQL SERVER 2008:</em><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Date </span><span style="color:blue;">AS </span><span style="color:black;">DATE<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Date </span><span style="color:blue;">= </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Date </span><span style="color:black;">OriginalDate</span></code></p>
<p style="text-align:justify;">ResultSet:<br />
<em>OriginalDate<br />
</em>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2007-12-22
</p>
<p style="text-align:justify;"><strong>TIME datatype </strong><strong>Explanation</strong></p>
<p style="text-align:justify;"><em>SQL SERVER 2005:</em><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Time </span><span style="color:blue;">AS </span><span style="color:black;">DATETIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Time </span><span style="color:blue;">= </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Time </span><span style="color:black;">OriginalTime</span><span style="color:gray;">, </span><span style="color:magenta;">CONVERT</span><span style="color:gray;">(</span><span style="color:blue;">VARCHAR</span><span style="color:gray;">(</span><span style="color:black;">10</span><span style="color:gray;">),</span><span style="color:#434343;">@Time</span><span style="color:gray;">,</span><span style="color:black;">108</span><span style="color:gray;">) </span><span style="color:black;">CastTime</span></code></p>
<p style="text-align:justify;">ResultSet:<br />
OriginalTime            CastTime<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;-<br />
2007-12-22 17:48:57.200 17:48:57</p>
<p style="text-align:justify;"><em>SQL SERVER 2008:</em><br />
<code style="font-size:12px;"><span style="color:blue;">DECLARE </span><span style="color:#434343;">@Time </span><span style="color:blue;">AS </span><span style="color:black;">TIME<br />
</span><span style="color:blue;">SET </span><span style="color:#434343;">@Time </span><span style="color:blue;">= </span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()<br />
</span><span style="color:blue;">SELECT </span><span style="color:#434343;">@Time </span><span style="color:black;">OriginalTime</span></code></p>
<p style="text-align:justify;">ResultSet:<br />
OriginalTime<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
17:48:57.2000000
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/448/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/448/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/448/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/448/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/448/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/448/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/448/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/448/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/448/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/448/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/448/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/448/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=448&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/12/23/sql-server-2008-new-datatypes-date-and-time/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQLAuthority News &#8211; Best Articles on SQLAuthority.com</title>
		<link>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/</link>
		<comments>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 14:00:25 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[DBA]]></category>
		<category><![CDATA[Data Warehousing]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Add-On]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL Backup and Restore]]></category>
		<category><![CDATA[SQL Coding Standards]]></category>
		<category><![CDATA[SQL Constraint and Keys]]></category>
		<category><![CDATA[SQL Cursor]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Download]]></category>
		<category><![CDATA[SQL Error Messages]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Humor]]></category>
		<category><![CDATA[SQL Index]]></category>
		<category><![CDATA[SQL Interview Questions and Answers]]></category>
		<category><![CDATA[SQL Joins]]></category>
		<category><![CDATA[SQL Performance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Security]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBCC]]></category>
		<category><![CDATA[SQL Stored Procedure]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[SQL Trigger]]></category>
		<category><![CDATA[SQL Utility]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/</guid>
		<description><![CDATA[SQL SERVER &#8211; Cursor to Kill All Process in Database
SQL SERVER &#8211; Find Stored Procedure Related to Table in Database &#8211; Search in All Stored procedure
SQL SERVER &#8211; Shrinking Truncate Log File &#8211; Log Full
SQL SERVER &#8211; Simple Example of Cursor
SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=395&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/01/sql-server-cursor-to-kill-all-process-in-database/">SQL SERVER &#8211; Cursor to Kill All Process in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/10/sql-server-find-stored-procedure-related-to-table-in-database-search-in-all-stored-procedure/">SQL SERVER &#8211; Find Stored Procedure Related to Table in Database &#8211; Search in All Stored procedure</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2006/12/30/sql-server-shrinking-truncate-log-file-log-full/">SQL SERVER &#8211; Shrinking Truncate Log File &#8211; Log Full</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/">SQL SERVER &#8211; Simple Example of Cursor</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/">SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper Case</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/25/sql-server-restore-database-backup-using-sql-script-t-sql/">SQL SERVER &#8211; Restore Database Backup using SQL Script (T-SQL)</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/02/28/sql-server-t-sql-script-to-find-the-cd-key-from-registry/">SQL SERVER &#8211; T-SQL Script to find the CD key from Registry</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/">SQL SERVER &#8211; Delete Duplicate Records &#8211; Rows</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/05/sql-server-quoted_identifier-onoff-and-ansi_null-onoff-explanation/">SQL SERVER &#8211; QUOTED_IDENTIFIER ON/OFF and ANSI_NULL ON/OFF Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/10/sql-server-union-vs-union-all-which-is-better-for-performance/">SQL SERVER &#8211; Union vs. Union All &#8211; Which is better for performance?</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/15/sql-server-dbcc-reseed-table-identity-value-reset-table-identity/">SQL SERVER &#8211; DBCC RESEED Table Identity Value &#8211; Reset Table Identity</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/">SQL SERVER &#8211; @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT &#8211; Retrieve Last Inserted Identity of Record</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/29/sql-server-difference-between-distinct-and-group-by-distinct-vs-group-by/">SQL SERVER &#8211; Difference between DISTINCT and GROUP BY &#8211; Distinct vs Group By</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scan-table-scan/">SQL SERVER &#8211; Index Seek Vs. Index Scan (Table Scan)</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/01/sql-server-tempdb-is-full-move-tempdb-from-one-drive-to-another-drive/">SQL SERVER &#8211; TempDB is Full. Move TempDB from one drive to another drive</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/03/sql-server-t-sql-paging-query-technique-comparison-sql-2000-vs-sql-2005/">SQL SERVER &#8211; T-SQL Paging Query Technique Comparison &#8211; SQL 2000 vs SQL 2005</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/05/sql-server-performance-optimization-of-sql-query-and-filegroups/">SQL SERVER &#8211; Performance Optimization of SQL Query and FileGroups</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/08/sql-server-search-text-field-charindex-vs-patindex/">SQL SERVER &#8211; Search Text Field &#8211; CHARINDEX vs PATINDEX</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/">SQL SERVER &#8211; 2005 Explanation of TRY…CATCH and ERROR Handling</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/13/sql-server-script-to-find-sql-server-on-network/">SQL SERVER &#8211; Script to find SQL Server on Network</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/13/sql-server-stored-procedures-advantages-and-best-advantage/">SQL SERVER &#8211; Stored Procedures Advantages and Best Advantage</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/">SQL SERVER &#8211; CASE Statement/Expression Examples and Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/22/sql-server-raid-configuration-raid-10/">SQL SERVER &#8211; Raid Configuration &#8211; RAID 10</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/23/sql-server-understanding-new-index-type-of-sql-server-2005-included-column-index-along-with-clustered-index-and-non-clustered-index/">SQL SERVER &#8211; Understanding new Index Type of SQL Server 2005 Included Column Index along with Clustered Index and Non-clustered Index</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/23/sql-server-query-to-find-seed-values-increment-values-and-current-identity-column-value-of-the-table/">SQL SERVER &#8211; Query to Find Seed Values, Increment Values and Current Identity Column value of the table</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/24/sql-server-six-properties-of-relational-tables/">SQL SERVER &#8211; Six Properties of Relational Tables</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/24/sql-server-trim-function-udf-trim/">SQL SERVER &#8211; TRIM() Function &#8211; UDF TRIM()</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/26/sql-server-difference-between-unique-index-vs-unique-constraint/">SQL SERVER &#8211; Difference between Unique Index vs Unique Constraint</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/27/sql-server-2005-locking-hints-and-examples/">SQL SERVER &#8211; 2005 Locking Hints and Examples</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/28/sql-server-good-better-and-best-programming-techniques/">SQL SERVER &#8211; Good, Better and Best Programming Techniques</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/">SQL SERVER &#8211; Random Number Generator Script &#8211; SQL Query</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/02/sql-server-2005-top-improvementsenhancements/">SQL SERVER &#8211; 2005 TOP Improvements/Enhancements</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/07/sql-server-20052000-examples-and-explanation-for-goto/">SQL SERVER &#8211; 2005/2000 Examples and Explanation for GOTO</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/11/sql-server-explanation-sql-command-go/">SQL SERVER &#8211; Explanation SQL Commando GO</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/12/sql-server-2005-list-all-the-database/">SQL SERVER &#8211; 2005 &#8211; List all the database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/">SQL SERVER &#8211; UDF &#8211; Function to Parse AlphaNumeric Characters from String</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/17/sql-server-disable-index-enable-index-alter-index/">SQL SERVER &#8211; Disable Index &#8211; Enable Index &#8211; ALTER Index</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/18/sql-server-2005-ssms-change-t-sql-batch-separator/">SQL SERVER &#8211; 2005 &#8211; SSMS Change T-SQL Batch Separator</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/20/sql-server-sql-code-formatter-tools/">SQL SERVER &#8211; SQL Code Formatter Tools</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/22/sql-server-2005-comparison-except-operator-vs-not-in/">SQL SERVER &#8211; 2005 Comparison EXCEPT operator vs. NOT IN</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/23/sql-server-2005-northwind-database-or-adventureworks-database-samples-databases/">SQL SERVER &#8211; 2005 NorthWind Database or AdventureWorks Database &#8211; Samples Databases</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/26/sql-server-2005-find-table-without-clustered-index-find-table-with-no-primary-key/">SQL SERVER &#8211; 2005 Find Table without Clustered Index &#8211; Find Table with no Primary Key</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/27/sql-server-2005-limiting-result-sets-by-using-tablesample-examples/">SQL SERVER &#8211; 2005 Limiting Result Sets by Using TABLESAMPLE &#8211; Examples</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/05/29/sql-server-2005-change-database-compatible-level-backward-compatibility/">SQL SERVER &#8211; 2005 Change Database Compatible Level &#8211; Backward Compatibility</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/01/sql-server-2005-constraint-on-varcharmax-field-to-limit-it-certain-length/">SQL SERVER &#8211; 2005 Constraint on VARCHAR(MAX) Field To Limit It Certain Length</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/06/sql-server-database-coding-standards-and-guidelines-complete-list-download/">SQL SERVER Database Coding Standards and Guidelines Complete List Download</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/08/sql-server-insert-multiple-records-using-one-insert-statement-use-of-union-all/">SQL SERVER &#8211; Insert Multiple Records Using One Insert Statement &#8211; Use of UNION ALL</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/">SQL SERVER &#8211; Retrieve &#8211; Select Only Date Part From DateTime &#8211; Best Practice</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/11/sql-server-2005-t-sql-paging-query-technique-comparison-over-and-row_number-cte-vs-derived-table/">SQL SERVER &#8211; 2005 T-SQL Paging Query Technique Comparison (OVER and ROW_NUMBER()) &#8211; CTE vs. Derived Table</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/14/sql-server-easy-sequence-of-select-from-join-where-group-by-having-order-by/">SQL SERVER &#8211; Easy Sequence of SELECT FROM JOIN WHERE GROUP BY HAVING ORDER BY</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/16/sql-server-udf-user-defined-function-to-strip-html-parse-html-no-regular-expression/">SQL SERVER &#8211; 2005 &#8211; UDF &#8211; User Defined Function to Strip HTML &#8211; Parse HTML &#8211; No Regular Expression</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/21/sql-server-retrieve-current-date-time-in-sql-server-current_timestamp-getdate-fn-now/">SQL SERVER &#8211; Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/22/sql-server-explanation-and-comparison-of-nullif-and-isnull/">SQL SERVER &#8211; Explanation and Comparison of NULLIF and ISNULL</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/23/sql-server-2005-row-overflow-data-explanation/">SQL SERVER &#8211; 2005 Row Overflow Data Explanation</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/06/24/sql-server-comparison-index-fragmentation-index-de-fragmentation-index-rebuild-sql-server-2000-and-sql-server-2005/">SQL SERVER &#8211; Comparison Index Fragmentation, Index De-Fragmentation, Index Rebuild &#8211; SQL SERVER 2000 and SQL SERVER 2005</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/03/sql-server-comparison-similarity-and-difference-temptable-vs-tempvariable/">SQL SERVER &#8211; Comparison : Similarity and Difference #TempTable vs @TempVariable</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/04/sql-server-definition-comparison-and-difference-between-having-and-where-clause/">SQL SERVER &#8211; Definition, Comparison and Difference between HAVING and WHERE Clause</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/05/sql-server-2005-best-practices-analyzer-tutorial-sample-example/">SQL SERVER &#8211; 2005 Best Practices Analyzer Tutorial &#8211; Sample Example</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/10/sql-server-2005-list-all-stored-procedure-modified-in-last-n-days/">SQL SERVER &#8211; 2005 &#8211; List All Stored Procedure Modified in Last N Days</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/11/sql-server-count-duplicate-records-rows/">SQL SERVER &#8211; Count Duplicate Records &#8211; Rows</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/17/sql-server-case-statement-in-order-by-clause-order-by-using-variable/">SQL SERVER &#8211; CASE Statement in ORDER BY Clause &#8211; ORDER BY using Variable</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/18/sql-server-restore-database-without-or-with-backup-everything-about-restore-and-backup/">SQL SERVER &#8211; Restore Database Without or With Backup &#8211; Everything About Restore and Backup</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/07/23/sql-server-udf-function-to-get-previous-and-next-work-day-exclude-saturday-and-sunday/">SQL SERVER &#8211; UDF &#8211; Function to Get Previous And Next Work Day &#8211; Exclude Saturday and Sunday</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/04/sql-server-one-thing-all-dba-must-know/">SQL SERVER &#8211; One Thing All DBA Must Know</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/07/sql-server-2005-list-tables-in-database-without-primary-key/">SQL SERVER &#8211; 2005 &#8211; List Tables in Database Without Primary Key</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/10/sql-server-2005-find-stored-procedure-create-date-and-modified-date/">SQL SERVER &#8211; 2005 &#8211; Find Stored Procedure Create Date and Modified Date</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/11/sql-server-udf-validate-integer-function/">SQL SERVER &#8211; UDF &#8211; Validate Integer Function</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/14/sql-server-what-is-sql-how-to-pronounce-sql/">SQL SERVER &#8211; What is SQL? How to pronounce SQL?</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/16/sql-server-2005-difference-and-similarity-between-newsequentialid-and-newid/">SQL SERVER &#8211; 2005 &#8211; Difference and Similarity Between NEWSEQUENTIALID() and NEWID()</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/17/sql-server-2005-explanation-and-script-for-online-index-operations-create-rebuild-drop/">SQL SERVER &#8211; 2005 &#8211; Explanation and Script for Online Index Operations &#8211; Create, Rebuild, Drop</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/">SQL SERVER &#8211; Find Last Day of Any Month &#8211; Current Previous Next</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/">SQL SERVER &#8211; T-SQL Script to Insert Carriage Return and New Line Feed in Code</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/24/sql-server-2005-t-sql-script-to-attach-and-detach-database/">SQL SERVER &#8211; 2005 &#8211; T-SQL Script to Attach and Detach Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/08/28/sql-server-actual-execution-plan-vs-estimated-execution-plan/">SQL SERVER &#8211; Actual Execution Plan vs. Estimated Execution Plan</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/03/sql-server-2005-search-stored-procedure-code-search-stored-procedure-text/">SQL SERVER &#8211; 2005 &#8211; Search Stored Procedure Code &#8211; Search Stored Procedure Text</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; Find Tables With Foreign Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-primary-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; Find Tables With Primary Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/06/sql-server-2005-introduction-and-explanation-to-sqlcmd/">SQL SERVER &#8211; 2005 &#8211; Introduction and Explanation to sqlcmd</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/">SQL SERVER &#8211; UDF &#8211; User Defined Function &#8211; Get Number of Days in Month</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/09/sql-server-2005-start-stop-restart-sql-server-from-command-prompt/">SQL SERVER &#8211; 2005 &#8211; Start Stop Restart SQL Server From Command Prompt</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/16/sql-server-2005-list-all-the-constraint-of-database-find-primary-key-and-foreign-key-constraint-in-database/">SQL SERVER &#8211; 2005 &#8211; List All The Constraint of Database &#8211; Find Primary Key and Foreign Key Constraint in Database</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/18/sql-server-udf-validate-positive-integer-function-validate-natural-integer-function/">SQL SERVER &#8211; UDF &#8211; Validate Positive Integer Function &#8211; Validate Natural Integer Function</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/09/25/sql-server-effect-of-transaction-on-local-variable-after-rollback-and-after-commit/">SQL SERVER &#8211; Effect of TRANSACTION on Local Variable &#8211; After ROLLBACK and After COMMIT</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/01/sql-server-2005-output-clause-example-and-explanation-with-insert-update-delete/">SQL SERVER &#8211; 2005 &#8211; OUTPUT Clause Example and Explanation with INSERT, UPDATE, DELETE</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/09/sql-server-2005-sample-example-of-ranking-functions-row_number-rank-dense_rank-ntile/">SQL SERVER &#8211; 2005 &#8211; Sample Example of RANKING Functions &#8211; ROW_NUMBER, RANK, DENSE_RANK, NTILE</a></p>
<p style="text-align:justify;"><a href="http://blog.sqlauthority.com/2007/10/16/sql-server-three-t-sql-script-to-create-primary-keys-on-table/">SQL SERVER &#8211; Three T-SQL Script to Create Primary Keys on Table</a></p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/395/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/395/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/395/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=395&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/11/04/sqlauthority-news-best-articles-on-sqlauthoritycom/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; Introduction and Example for DATEFORMAT Command</title>
		<link>http://blog.sqlauthority.com/2007/09/28/sql-server-introduction-and-example-for-dateformat-command/</link>
		<comments>http://blog.sqlauthority.com/2007/09/28/sql-server-introduction-and-example-for-dateformat-command/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 14:00:45 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Documentation]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/28/sql-server-introduction-and-example-for-dateformat-command/</guid>
		<description><![CDATA[While doing surprise code review of Jr. DBA I found interesting syntax DATEFORMAT. This keywords is very less used as CONVERT and CAST can do much more than this command. It is still interesting to learn about learn about this new syntax.
Sets the order of the dateparts (month/day/year) for entering datetime or smalldatetime data. This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=349&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">While doing surprise code review of Jr. DBA I found interesting syntax DATEFORMAT. This keywords is very less used as <a href="http://blog.sqlauthority.com/2007/06/10/sql-server-retrieve-select-only-date-part-from-datetime-best-practice/" target="_blank">CONVERT and CAST</a> can do much more than this command. It is still interesting to learn about learn about this new syntax.</p>
<p style="text-align:justify;">Sets the order of the dateparts (month/day/year) for entering datetime or smalldatetime data. This command allows you to input strings that would normally not be recognized by SQL server as dates. The SET DATEFORMAT command lets you specify order of data parts. The options for DATEFORMAT are mdy, dmy, ymd, ydm, myd, or dym. The default DATEFORMAT is mdy. This commands allows to INSERT/UPDATE dates with different formats without doing any special data conversions.The setting of SET DATEFORMAT is set at execute or run time and not at parse time. Following example demonstrate how character string can be converted to proper dateformat using SET DATEFORMAT command.</p>
<p style="text-align:justify;"><strong>Example:</strong><br />
<code style="font-size:12px;"><span style="color:blue;">CREATE TABLE </span><span style="color:#434343;">#tempTable </span><span style="color:gray;">(</span><span style="color:black;">DateFormatSample SMALLDATETIME</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:black;">DATEFORMAT MDY<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">#tempTable<br />
</span><span style="color:blue;">VALUES </span><span style="color:gray;">(</span><span style="color:red;">'09/28/2007'</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:black;">DATEFORMAT YDM<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">#tempTable<br />
</span><span style="color:blue;">VALUES </span><span style="color:gray;">(</span><span style="color:red;">'2007/28/09'</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SET </span><span style="color:black;">DATEFORMAT YMD<br />
</span><span style="color:blue;">INSERT INTO </span><span style="color:#434343;">#tempTable<br />
</span><span style="color:blue;">VALUES </span><span style="color:gray;">(</span><span style="color:red;">'2007/08/28'</span><span style="color:gray;">)<br />
</span><span style="color:blue;">SELECT </span><span style="color:black;">DateFormatSample<br />
</span><span style="color:blue;">FROM </span><span style="color:#434343;">#tempTable<br />
</span><span style="color:blue;">DROP TABLE </span><span style="color:#434343;">#tempTable</span></code><br />
<strong>Resultset:</strong><br />
DateFormatSample<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
2007-09-28 00:00:00<br />
2007-09-28 00:00:00<br />
2007-08-28 00:00:00
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/349/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/349/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/349/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=349&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/09/28/sql-server-introduction-and-example-for-dateformat-command/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL SERVER &#8211; UDF &#8211; User Defined Function &#8211; Get Number of Days in Month</title>
		<link>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/</link>
		<comments>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 14:00:06 +0000</pubDate>
		<dc:creator>pinaldave</dc:creator>
				<category><![CDATA[Pinal Dave]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Authority]]></category>
		<category><![CDATA[SQL DateTime]]></category>
		<category><![CDATA[SQL Function]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[T SQL]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/</guid>
		<description><![CDATA[Following User Defined Function (UDF) returns the numbers of days in month. It is very simple yet very powerful and full proof UDF.
CREATE FUNCTION [dbo].[udf_GetNumDaysInMonth] ( @myDateTime DATETIME )
RETURNS INT
AS
BEGIN
DECLARE @rtDate INT
SET @rtDate = CASE WHEN MONTH(@myDateTime)
IN (1, 3, 5, 7, 8, 10, 12) THEN 31
WHEN MONTH(@myDateTime) IN (4, 6, 9, 11) THEN 30
ELSE CASE [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=326&subd=sqlauthority&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:justify;">Following User Defined Function (UDF) returns the numbers of days in month. It is very simple yet very powerful and full proof UDF.<br />
<code style="font-size:12px;"><span style="color:blue;">CREATE FUNCTION </span><span style="color:black;">[dbo].[udf_GetNumDaysInMonth] </span><span style="color:gray;">( </span><span style="color:#434343;">@myDateTime </span><span style="color:black;">DATETIME </span><span style="color:gray;">)<br />
</span><span style="color:blue;">RETURNS INT<br />
AS<br />
BEGIN<br />
DECLARE </span><span style="color:#434343;">@rtDate </span><span style="color:blue;">INT<br />
SET </span><span style="color:#434343;">@rtDate </span><span style="color:blue;">= </span><span style="color:magenta;">CASE </span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@myDateTime</span><span style="color:gray;">)<br />
</span><span style="color:blue;">IN </span><span style="color:gray;">(</span><span style="color:black;">1</span><span style="color:gray;">, </span><span style="color:black;">3</span><span style="color:gray;">, </span><span style="color:black;">5</span><span style="color:gray;">, </span><span style="color:black;">7</span><span style="color:gray;">, </span><span style="color:black;">8</span><span style="color:gray;">, </span><span style="color:black;">10</span><span style="color:gray;">, </span><span style="color:black;">12</span><span style="color:gray;">) </span><span style="color:blue;">THEN </span><span style="color:black;">31<br />
</span><span style="color:blue;">WHEN </span><span style="color:magenta;">MONTH</span><span style="color:gray;">(</span><span style="color:#434343;">@myDateTime</span><span style="color:gray;">) </span><span style="color:blue;">IN </span><span style="color:gray;">(</span><span style="color:black;">4</span><span style="color:gray;">, </span><span style="color:black;">6</span><span style="color:gray;">, </span><span style="color:black;">9</span><span style="color:gray;">, </span><span style="color:black;">11</span><span style="color:gray;">) </span><span style="color:blue;">THEN </span><span style="color:black;">30<br />
</span><span style="color:blue;">ELSE </span><span style="color:magenta;">CASE </span><span style="color:blue;">WHEN </span><span style="color:gray;">(</span><span style="color:magenta;">YEAR</span><span style="color:gray;">(</span><span style="color:#434343;">@myDateTime</span><span style="color:gray;">) % </span><span style="color:black;">4 </span><span style="color:blue;">= </span><span style="color:black;">0<br />
</span><span style="color:gray;">AND<br />
</span><span style="color:magenta;">YEAR</span><span style="color:gray;">(</span><span style="color:#434343;">@myDateTime</span><span style="color:gray;">) % </span><span style="color:black;">100 </span><span style="color:gray;">!= </span><span style="color:black;">0</span><span style="color:gray;">)<br />
OR<br />
(</span><span style="color:magenta;">YEAR</span><span style="color:gray;">(</span><span style="color:#434343;">@myDateTime</span><span style="color:gray;">) % </span><span style="color:black;">400 </span><span style="color:blue;">= </span><span style="color:black;">0</span><span style="color:gray;">)<br />
</span><span style="color:blue;">THEN </span><span style="color:black;">29<br />
</span><span style="color:blue;">ELSE </span><span style="color:black;">28 </span><span style="color:blue;">END<br />
END<br />
RETURN </span><span style="color:#434343;">@rtDate<br />
</span><span style="color:blue;">END<br />
</span><span style="color:black;">GO<br />
</span></code><br />
Run following script in Query Editor:<br />
<code style="font-size:12px;"><span style="color:blue;">SELECT </span><span style="color:black;">dbo.udf_GetNumDaysInMonth</span><span style="color:gray;">(</span><span style="color:magenta;">GETDATE</span><span style="color:gray;">()) </span><span style="color:black;">NumDaysInMonth<br />
GO<br />
</span></code><br />
<strong><em>ResultSet:</em></strong><br />
NumDaysInMonth<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
31
</p>
<p style="text-align:justify;">Reference : <strong>Pinal Dave (</strong><a href="http://blog.SQLAuthority.com" target="_blank"><strong>http://blog.SQLAuthority.com</strong></a><strong>)</strong></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sqlauthority.wordpress.com/326/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sqlauthority.wordpress.com/326/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sqlauthority.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sqlauthority.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sqlauthority.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sqlauthority.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sqlauthority.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sqlauthority.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sqlauthority.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sqlauthority.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sqlauthority.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sqlauthority.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.sqlauthority.com&blog=668536&post=326&subd=sqlauthority&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.sqlauthority.com/2007/09/08/sql-server-udf-user-defined-function-get-number-of-days-in-month/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/48aa5a2264e8a27d802bb22ab6ccf688?s=96&#38;d=identicon" medium="image">
			<media:title type="html">pinaldave</media:title>
		</media:content>
	</item>
	</channel>
</rss>