Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case with date comparison 1

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
Hi
I'm attempting to extract data from a table and can't get my head around datediff or datepart. If date is less than 1 Jan 2004, I don't want the value of the column.
How do I code the below psuedo-code correctly ?
case RunDate when < &quot;1 Jan 2004&quot; then 0 else CurrYrCGCSalesYTD

Thanks in advance

Dickie Bird (:)-)))
 
Code:
case when rundate >= '2004-01-01' CurrYrCGCSalesYTD end

0 is not a valid date, the above will return null if rundate is less than 1 jan 2004
 
Thanks SwampBoogie - I'll give it a try with :
case when rundate >= '2004-01-01' CurrYrCGCSalesYTD else 0 end

to return either the value of the column CurrYrCGCSalesYTD
or zero.
Cheers





Dickie Bird (:)-)))
 
Hmmmm - Still not right :
select AgentCode,AgentName,
CurrYrTotalSalesMonth,
case RunDate when >= '2004-01-01' then CurrYrCGCSalesYTD else 0 end,
case RunDate when >= '2004-01-01' then PercentChangeMonthTotal else 0 end,

CurrYrTCQClbSalesMonth,
CurrYrTCQNetSalesMonth,
CurrYrTCQTelSalesMonth from atable

Results in Incorrect syntax near '>'.


Dickie Bird (:)-)))
 
Code:
elect AgentCode,AgentName,  
          CurrYrTotalSalesMonth,
          case when RunDate >= '2004-01-01' then CurrYrCGCSalesYTD else 0 end,
          case when RunDate >= '2004-01-01' then PercentChangeMonthTotal else 0 end,
          
          CurrYrTCQClbSalesMonth,
          CurrYrTCQNetSalesMonth,
          CurrYrTCQTelSalesMonth from atable
 
Thanks again SwampBoogie - A case of case and when and then!

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top