If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Year function in Case statement does not work?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-07-03, 08:53
kburns1649 kburns1649 is offline
Registered User
 
Join Date: Nov 2003
Posts: 9
Question Year function in Case statement does not work?

A. - this item does not work with Year function in SELECT CASE statement

SELECT f.EFF_DT, CASE f.END_DT WHEN YEAR(f.END_DT) = 9999 THEN 'Present' ELSE f.END_DT END
From Customer F


B. Same 'YEAR' function does work in WHERE clause.

SELECT f.EFF_DT
FROM Customer F
Where YEAR(f.END_DT) = 9999


Any thoughts, most appreciated...Thanks,
Marcel K.
Reply With Quote
  #2 (permalink)  
Old 11-07-03, 09:21
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
You have 2 problems:

1. f.END_DT and "present" are not the same datatype.

2. Wrong syntax for case. Try this (using current date instead of "present":

SELECT f.END_DT,
CASE YEAR(f.END_DT)
WHEN 9999
THEN current date [or anything in external date format]
ELSE
f.END_DT
END
From Customer F...
Reply With Quote
  #3 (permalink)  
Old 11-07-03, 09:33
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
However...

You can do this to get the datatypes the same:

SELECT f.END_DT,
CASE YEAR(f.END_DT)
WHEN 9999
THEN 'present'
ELSE
cast(f.END_DT as char(10))
END
From Customer F...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On