<?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>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 10 Feb 2012 02:12:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Ade Bunky</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-158419</link>
		<dc:creator><![CDATA[Ade Bunky]]></dc:creator>
		<pubDate>Wed, 17 Aug 2011 14:32:14 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-158419</guid>
		<description><![CDATA[Simply write.
 SELECT DATENAME(WEEKDAY, GETDATE())

WHY ALL THIS?:
&quot;
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,GETDATE())+@@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 7 THEN &#039;Saturday&#039;
END
RETURN (@rtDayofWeek)
END
GO
SELECT dbo.udf_DayOfWeek(GETDATE())
&quot;]]></description>
		<content:encoded><![CDATA[<p>Simply write.<br />
 SELECT DATENAME(WEEKDAY, GETDATE())</p>
<p>WHY ALL THIS?:<br />
&#8221;<br />
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<br />
&#8211; like wise for Monday we need to subtract 2 and so on<br />
SET @weekDay = ((DATEPART(dw,GETDATE())+@@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 7 THEN &#8216;Saturday&#8217;<br />
END<br />
RETURN (@rtDayofWeek)<br />
END<br />
GO<br />
SELECT dbo.udf_DayOfWeek(GETDATE())<br />
&#8220;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-58407</link>
		<dc:creator><![CDATA[Joe]]></dc:creator>
		<pubDate>Thu, 10 Dec 2009 19:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-58407</guid>
		<description><![CDATA[Use B
select datename(weekday,date) as day,sum(amount)as sales
from  afa
where  afatypex in (63) 
and date &gt;= &#039;7/1/2008&#039;
and date &lt;&#039;7/1/2009&#039;
Group by date 
Order by date asc

This simple query gives me the sales amounts by weekday Monday thru Sunday which is great but what I&#039;m wanting to do is strip out days Sun thru Wednesday for a grand total for the entire lenth of data

Example:

Monday	       68874.0000
Tuesday	       91701.0000
Wednesday  223098.0000
Thursday	       74457.0000
Friday	     114947.0000
Saturday	     252631.0000
Sunday	       47100.0000
Monday	       68874.0000
Tuesday	       91701.0000
Wednesday  223098.0000
Thursday	       74457.0000
Friday	     114947.0000
Saturday	     252631.0000
Sunday	       47100.0000

maybe I should use the datepart(weekday,date) and then in the where clause say date like &#039;%7,1,2,3,4%&#039; or date in (7,1,2,3,4) but it won&#039;t let me do that?

Anyone have a suggestions?]]></description>
		<content:encoded><![CDATA[<p>Use B<br />
select datename(weekday,date) as day,sum(amount)as sales<br />
from  afa<br />
where  afatypex in (63)<br />
and date &gt;= &#8217;7/1/2008&#8242;<br />
and date &lt;&#039;7/1/2009&#039;<br />
Group by date<br />
Order by date asc</p>
<p>This simple query gives me the sales amounts by weekday Monday thru Sunday which is great but what I&#039;m wanting to do is strip out days Sun thru Wednesday for a grand total for the entire lenth of data</p>
<p>Example:</p>
<p>Monday	       68874.0000<br />
Tuesday	       91701.0000<br />
Wednesday  223098.0000<br />
Thursday	       74457.0000<br />
Friday	     114947.0000<br />
Saturday	     252631.0000<br />
Sunday	       47100.0000<br />
Monday	       68874.0000<br />
Tuesday	       91701.0000<br />
Wednesday  223098.0000<br />
Thursday	       74457.0000<br />
Friday	     114947.0000<br />
Saturday	     252631.0000<br />
Sunday	       47100.0000</p>
<p>maybe I should use the datepart(weekday,date) and then in the where clause say date like &#039;%7,1,2,3,4%&#039; or date in (7,1,2,3,4) but it won&#039;t let me do that?</p>
<p>Anyone have a suggestions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://blog.sqlauthority.com/2008/05/23/sql-server-sql-server-udf-get-the-day-of-the-week-function-part-2/#comment-58334</link>
		<dc:creator><![CDATA[Joe]]></dc:creator>
		<pubDate>Tue, 08 Dec 2009 22:54:04 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=613#comment-58334</guid>
		<description><![CDATA[Do you know how to get the actual weekday name on a date function.

i.e.

Mon
Tues
Wed

I think it&#039;s 

SELECT DATENAME(dw, GETDATE()) but it&#039;s not giving me the actual name of the day of the week?]]></description>
		<content:encoded><![CDATA[<p>Do you know how to get the actual weekday name on a date function.</p>
<p>i.e.</p>
<p>Mon<br />
Tues<br />
Wed</p>
<p>I think it&#8217;s </p>
<p>SELECT DATENAME(dw, GETDATE()) but it&#8217;s not giving me the actual name of the day of the week?</p>
]]></content:encoded>
	</item>
	<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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[[...] 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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[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><![CDATA[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>

