﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server Newbies  / Case Statement - DateDiff and DatePart / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 04:24:35 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Case Statement - DateDiff and DatePart</title><link>http://www.sqlservercentral.com/Forums/Topic1426132-1292-1.aspx</link><description>At the moment you have it written like an IF Statement[code="sql"]CASE     WHEN conditional_a = conditional_b THEN something    ELSE conditional_a = conditional_c THEN something_else    ELSE Default_SomethingEND    [/code] With CASE statements you write them like this[code="sql"]CASE     WHEN conditional_a = conditional_b THEN something    WHEN conditional_a = conditional_c THEN something_else    ELSE  Default_SomethingEND[/code]Hope this helps.</description><pubDate>Mon, 04 Mar 2013 02:52:22 GMT</pubDate><dc:creator>Jason-299789</dc:creator></item><item><title>RE: Case Statement - DateDiff and DatePart</title><link>http://www.sqlservercentral.com/Forums/Topic1426132-1292-1.aspx</link><description>Don't worry all sorted:Declare @DOB DatetimeDeclare @Today DatetimeSet @DOB = '01 November 1971'Set @Today = '01 November 2011'SELECTCASE WHEN DatePart(Month, @Today) &amp;lt; Datepart(Month,@DOB) THEN (Datediff(Year,@DOB,@Today) - 1)	 WHEN DatePart(Month, @Today)  &amp;gt; Datepart(Month,@DOB) THEN Datediff(Year,@DOB,@Today)     WHEN DatePart(Month, @Today) = Datepart(Month,@DOB) THEN CASE     WHEN DatePart(Day, @Today)  &amp;lt; Datepart(Day,@DOB) THEN (Datediff(Year,@DOB,@Today) - 1 )	 WHEN DatePart(Day, @Today)  &amp;gt;= Datepart(Day,@DOB) THEN (Datediff(Year,@DOB,@Today) )	 END	 END AS How_Old_Am_I</description><pubDate>Mon, 04 Mar 2013 02:49:53 GMT</pubDate><dc:creator>wafw1971</dc:creator></item><item><title>Case Statement - DateDiff and DatePart</title><link>http://www.sqlservercentral.com/Forums/Topic1426132-1292-1.aspx</link><description>I have been asked to come up with a case statement that gives me the date of birth, no I know there are easier ways to do it but its about writing the actual statement which I have done but I have got a bit confused.Can you Help?Declare @DOB DatetimeDeclare @Today DatetimeSet @DOB = '01 November 1971'Set @Today = GETDATE()SELECT Datediff(Year,@DOB,@Today) AS Years, Datepart(Month,@DOB) As DOB_Month, Datepart(Day, @DOB) as DOB_Day,DatePart(Month, @Today) As Current_Month, Datepart(Day,@Today) AS Current_DayCASE WHEN DatePart(Month, @Today) &amp;lt; Datepart(Month,@DOB) THEN Datediff(Year,@DOB,@Today) THEN -1 ELSEDatePart(Month, @Today) = Datepart(Month,@DOB) THEN Datepart(Day,@Today) &amp;lt; Datepart(Day, @DOB) THEN Datediff(Year,@DOB,@Today) THEN -1 ELSE END</description><pubDate>Mon, 04 Mar 2013 02:14:19 GMT</pubDate><dc:creator>wafw1971</dc:creator></item></channel></rss>