<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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: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>Comments on: SQL SERVER &#8211; SQL SERVER &#8211; UDF &#8211; Get the Day of the Week Function &#8211; Part 2</title>
	<atom:link href="http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Kristjan Farrugia</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-57083</link>
		<dc:creator>Kristjan Farrugia</dc:creator>
		<pubDate>Tue, 27 Oct 2009 17:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-57083</guid>
		<description>Thanks Pinal :)</description>
		<content:encoded><![CDATA[<p>Thanks Pinal :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: george</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-53948</link>
		<dc:creator>george</dc:creator>
		<pubDate>Wed, 22 Jul 2009 08:58:34 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-53948</guid>
		<description>is this work with sql 2000</description>
		<content:encoded><![CDATA[<p>is this work with sql 2000</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ray</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-45721</link>
		<dc:creator>Ray</dc:creator>
		<pubDate>Mon, 19 Jan 2009 05:21:49 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-45721</guid>
		<description>Thanks a lot for this - right on the button and saved me a deal of work.

Great stuff

Ray

Sydney
Australia</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this &#8211; right on the button and saved me a deal of work.</p>
<p>Great stuff</p>
<p>Ray</p>
<p>Sydney<br />
Australia</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - SQL SERVER - UDF - Get the Day of the Week Function - Part 3 Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-39116</link>
		<dc:creator>SQL SERVER - SQL SERVER - UDF - Get the Day of the Week Function - Part 3 Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Mon, 09 Jun 2008 16:47:56 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-39116</guid>
		<description>[...] 27, 2008 by pinaldave    Datetime functions and stored procedures always interests me. Nanda Kumar has suggested modification to previous written article about SQL SERVER - SQL SERVER - UDF - Get [...]</description>
		<content:encoded><![CDATA[<p>[...] 27, 2008 by pinaldave    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 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nanda KUmar</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-39088</link>
		<dc:creator>Nanda KUmar</dc:creator>
		<pubDate>Mon, 09 Jun 2008 05:44:33 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-39088</guid>
		<description>Hi Pinal,

Actually the function u posted is returning &#039;NULL&#039; for Saturdays and works for rest all days.  And you didn&#039;t use the given argument inside the funciton instead you used getdate().  this also returns error. The following is working...

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 Sunday as the First day like wise for Monday we need to subtract 2 and so on
	set @weekDay=((DATEPART(dw,@dtDate)+@@DATEFIRST-7)%7)
    SELECT @rtDayofWeek = CASE @weekDay
                    WHEN 1 THEN &#039;Sunday&#039;
                    WHEN 2 THEN &#039;Monday&#039;
                    WHEN 3 THEN &#039;Tuesday&#039;
                    WHEN 4 THEN &#039;Wednesday&#039;
                    WHEN 5 THEN &#039;Thursday&#039;
                    WHEN 6 THEN &#039;Friday&#039;
                    WHEN 0 THEN &#039;Saturday&#039;
        END
    RETURN (@rtDayofWeek)
    END
GO

select dbo.udf_dayofweek(getdate())

I&#039;m happy to reply this post as Novice DBA

Nandha</description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Actually the function u posted is returning &#8216;NULL&#8217; for Saturdays and works for rest all days.  And you didn&#8217;t use the given argument inside the funciton instead you used getdate().  this also returns error. The following is working&#8230;</p>
<p>Create FUNCTION dbo.udf_DayOfWeek(@dtDate DATETIME)<br />
RETURNS VARCHAR(10)<br />
            AS<br />
    BEGIN<br />
    DECLARE @rtDayofWeek VARCHAR(10)<br />
    DECLARE @weekDay INT<br />
&#8211;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 />
	set @weekDay=((DATEPART(dw,@dtDate)+@@DATEFIRST-7)%7)<br />
    SELECT @rtDayofWeek = CASE @weekDay<br />
                    WHEN 1 THEN &#8216;Sunday&#8217;<br />
                    WHEN 2 THEN &#8216;Monday&#8217;<br />
                    WHEN 3 THEN &#8216;Tuesday&#8217;<br />
                    WHEN 4 THEN &#8216;Wednesday&#8217;<br />
                    WHEN 5 THEN &#8216;Thursday&#8217;<br />
                    WHEN 6 THEN &#8216;Friday&#8217;<br />
                    WHEN 0 THEN &#8216;Saturday&#8217;<br />
        END<br />
    RETURN (@rtDayofWeek)<br />
    END<br />
GO</p>
<p>select dbo.udf_dayofweek(getdate())</p>
<p>I&#8217;m happy to reply this post as Novice DBA</p>
<p>Nandha</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sudev Gandhi</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-39011</link>
		<dc:creator>Sudev Gandhi</dc:creator>
		<pubDate>Thu, 05 Jun 2008 17:11:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-39011</guid>
		<description>Hi Pinal,

I&#039;m also surprised to see effort you&#039;ve put to retrive Day of week for a given date. DATENAME function can perform this task pretty well.

I&#039;m sure you must be aware of this function but you might have face some issue with it. Could you please share those issues wit DATENAME function?

Thanks &amp; Regards,
Sudev Gandhi
[http://sudev.blogspot.com</description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I&#8217;m also surprised to see effort you&#8217;ve put to retrive Day of week for a given date. DATENAME function can perform this task pretty well.</p>
<p>I&#8217;m sure you must be aware of this function but you might have face some issue with it. Could you please share those issues wit DATENAME function?</p>
<p>Thanks &amp; Regards,<br />
Sudev Gandhi<br />
[http://sudev.blogspot.com</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Worth</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-38977</link>
		<dc:creator>Simon Worth</dc:creator>
		<pubDate>Wed, 04 Jun 2008 12:35:01 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-38977</guid>
		<description>I&#039;m still a little confused as to why you would want to go through the trouble of calling a UDF with 18 to 20 lines of code when the SQL Server development team has already done it for you.

SELECT DATENAME(dw, GETDATE())

I do understand the fun that can be had with trying to solve complex problems with T-SQL, but this is not one of those complex problems.  It&#039;s built in to the system for anyone to use when ever they want.</description>
		<content:encoded><![CDATA[<p>I&#8217;m still a little confused as to why you would want to go through the trouble of calling a UDF with 18 to 20 lines of code when the SQL Server development team has already done it for you.</p>
<p>SELECT DATENAME(dw, GETDATE())</p>
<p>I do understand the fun that can be had with trying to solve complex problems with T-SQL, but this is not one of those complex problems.  It&#8217;s built in to the system for anyone to use when ever they want.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
