<?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/"
		>
<channel>
	<title>Comments on: Conditional Where Clause</title>
	<atom:link href="http://sqlserverplanet.com/sql/conditional-where-clause/feed" rel="self" type="application/rss+xml" />
	<link>http://sqlserverplanet.com/sql/conditional-where-clause</link>
	<description>Tips and Articles on SQL Server</description>
	<lastBuildDate>Mon, 06 Feb 2012 13:36:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Ramon</title>
		<link>http://sqlserverplanet.com/sql/conditional-where-clause/comment-page-1#comment-977</link>
		<dc:creator>Ramon</dc:creator>
		<pubDate>Mon, 21 Nov 2011 07:15:58 +0000</pubDate>
		<guid isPermaLink="false">http://sqlserverplanet.com/?p=899#comment-977</guid>
		<description>Wow Greate tutorial.... Thanx</description>
		<content:encoded><![CDATA[<p>Wow Greate tutorial&#8230;. Thanx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rajani</title>
		<link>http://sqlserverplanet.com/sql/conditional-where-clause/comment-page-1#comment-669</link>
		<dc:creator>rajani</dc:creator>
		<pubDate>Mon, 23 May 2011 16:54:03 +0000</pubDate>
		<guid isPermaLink="false">http://sqlserverplanet.com/?p=899#comment-669</guid>
		<description>Thank You!! 
I stumbled accross this today and it helped fix up my code perfectly.</description>
		<content:encoded><![CDATA[<p>Thank You!!<br />
I stumbled accross this today and it helped fix up my code perfectly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harvey</title>
		<link>http://sqlserverplanet.com/sql/conditional-where-clause/comment-page-1#comment-481</link>
		<dc:creator>Harvey</dc:creator>
		<pubDate>Wed, 02 Feb 2011 20:11:47 +0000</pubDate>
		<guid isPermaLink="false">http://sqlserverplanet.com/?p=899#comment-481</guid>
		<description>Dereck...Nevermind.  I figured out what needed to be done.  Thanks anyway!

-Harvey</description>
		<content:encoded><![CDATA[<p>Dereck&#8230;Nevermind.  I figured out what needed to be done.  Thanks anyway!</p>
<p>-Harvey</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harvey</title>
		<link>http://sqlserverplanet.com/sql/conditional-where-clause/comment-page-1#comment-480</link>
		<dc:creator>Harvey</dc:creator>
		<pubDate>Wed, 02 Feb 2011 19:16:19 +0000</pubDate>
		<guid isPermaLink="false">http://sqlserverplanet.com/?p=899#comment-480</guid>
		<description>Why it keeps gettign cut off...I don&#039;t know.  But here is another attempt at pasting it in;

  CASE WHEN DATEPART(mm, GetDate()) = 1  then
           (DatePart(dd, pl.Plcmt_From_Dt) &gt;= 11 
		and DatePart(mm, pl.Plcmt_From_Dt) = 12
		and DatePart(Year, pl.Plcmt_From_Dt) = DatePart(Year, GetDate())-1
		OR
        DatePart(dd, pl.Plcmt_From_Dt) = 11 AND (DATEPART(mm, pl.Plcmt_From_Dt) = DATEPART(mm, GETDATE())-1
         and DATEPART(Year, pl.Plcmt_From_Dt) = DATEPART(Year, GETDATE()))
        OR
         DATEPART(dd, pl.Plcmt_From_Dt) &lt;= 10 AND DATEPART(mm, pl.Plcmt_From_Dt) = DATEPART(mm, GETDATE()) AND			 DATEPART(Year, pl.Plcmt_From_Dt) = DATEPART(Year, GETDATE())
         end</description>
		<content:encoded><![CDATA[<p>Why it keeps gettign cut off&#8230;I don&#8217;t know.  But here is another attempt at pasting it in;</p>
<p>  CASE WHEN DATEPART(mm, GetDate()) = 1  then<br />
           (DatePart(dd, pl.Plcmt_From_Dt) &gt;= 11<br />
		and DatePart(mm, pl.Plcmt_From_Dt) = 12<br />
		and DatePart(Year, pl.Plcmt_From_Dt) = DatePart(Year, GetDate())-1<br />
		OR<br />
        DatePart(dd, pl.Plcmt_From_Dt) = 11 AND (DATEPART(mm, pl.Plcmt_From_Dt) = DATEPART(mm, GETDATE())-1<br />
         and DATEPART(Year, pl.Plcmt_From_Dt) = DATEPART(Year, GETDATE()))<br />
        OR<br />
         DATEPART(dd, pl.Plcmt_From_Dt) &lt;= 10 AND DATEPART(mm, pl.Plcmt_From_Dt) = DATEPART(mm, GETDATE()) AND			 DATEPART(Year, pl.Plcmt_From_Dt) = DATEPART(Year, GETDATE())<br />
         end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harvey</title>
		<link>http://sqlserverplanet.com/sql/conditional-where-clause/comment-page-1#comment-477</link>
		<dc:creator>Harvey</dc:creator>
		<pubDate>Wed, 02 Feb 2011 19:09:05 +0000</pubDate>
		<guid isPermaLink="false">http://sqlserverplanet.com/?p=899#comment-477</guid>
		<description>Dereck,

  I just subscribed to your newsletter and commented after using one of your posts to use the correct syntax for CAST functions.  I have a question and am hoping that you can help me.  I am writing a query where I am attempting to use a CASE expression in the WHERE clause using DATEPART. I am trying to build it so that if the month that a report is being run is January then to return records that are from the 11th of December of last year through the 10th of January of the current year ELSE return the records for the same date range of the current year.  The code that I have is as follows;

CASE WHEN DATEPART(mm, GetDate()) = 1  then
           (DatePart(dd, pl.Plcmt_From_Dt) &gt;= 11 
		and DatePart(mm, pl.Plcmt_From_Dt) = 12
		and DatePart(Year, pl.Plcmt_From_Dt) = DatePart(Year, GetDate())-1
		OR
        DatePart(dd, pl.Plcmt_From_Dt) = 11 AND (DATEPART(mm, pl.Plcmt_From_Dt) = DATEPART(mm, GETDATE())-1
         and DATEPART(Year, pl.Plcmt_From_Dt) = DATEPART(Year, GETDATE()))
        OR
         DATEPART(dd, pl.Plcmt_From_Dt) &#039;.

Any help you can offer would be greatly appreciated!

Sincerely,
Harvey</description>
		<content:encoded><![CDATA[<p>Dereck,</p>
<p>  I just subscribed to your newsletter and commented after using one of your posts to use the correct syntax for CAST functions.  I have a question and am hoping that you can help me.  I am writing a query where I am attempting to use a CASE expression in the WHERE clause using DATEPART. I am trying to build it so that if the month that a report is being run is January then to return records that are from the 11th of December of last year through the 10th of January of the current year ELSE return the records for the same date range of the current year.  The code that I have is as follows;</p>
<p>CASE WHEN DATEPART(mm, GetDate()) = 1  then<br />
           (DatePart(dd, pl.Plcmt_From_Dt) &gt;= 11<br />
		and DatePart(mm, pl.Plcmt_From_Dt) = 12<br />
		and DatePart(Year, pl.Plcmt_From_Dt) = DatePart(Year, GetDate())-1<br />
		OR<br />
        DatePart(dd, pl.Plcmt_From_Dt) = 11 AND (DATEPART(mm, pl.Plcmt_From_Dt) = DATEPART(mm, GETDATE())-1<br />
         and DATEPART(Year, pl.Plcmt_From_Dt) = DATEPART(Year, GETDATE()))<br />
        OR<br />
         DATEPART(dd, pl.Plcmt_From_Dt) &#8216;.</p>
<p>Any help you can offer would be greatly appreciated!</p>
<p>Sincerely,<br />
Harvey</p>
]]></content:encoded>
	</item>
</channel>
</rss>

