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 > Select questions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-27-03, 14:20
staryang staryang is offline
Registered User
 
Join Date: Nov 2003
Posts: 4
Talking Select questions

this based on Sample

I tried to do this:

db2 select firstnme,midinit,lastname,birthdate,YEAR(C
URRENT DATE) - YEAR(birthdate) as age from employee where YEAR(CURRENT DATE) - YEAR(birthdate) between 65 and 1000


It will give me a list who is older than 65

but

db2 select firstnme,midinit,lastname,birthdate,YEAR(C
URRENT DATE) - YEAR(birthdate) as age from employee where YEAR(CURRENT DATE) - YEAR(birthdate) > 65

wont work...

Could anyone tell me why? Thanks
Reply With Quote
  #2 (permalink)  
Old 11-27-03, 14:40
GertK GertK is offline
Registered User
 
Join Date: Nov 2003
Location: Netherlands
Posts: 96
Are you executing this from the command line?

If so you need to surround your query with " , otherwise the '>' will be recognized as a output redirecter.

If not, which message do you get?
Reply With Quote
  #3 (permalink)  
Old 11-27-03, 15:05
staryang staryang is offline
Registered User
 
Join Date: Nov 2003
Posts: 4
oh..yes, u r right... it output to a txt file
Reply With Quote
  #4 (permalink)  
Old 11-27-03, 15:07
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
As GertK said, put double quotes around the select (but after the DB2 command) if issued from command prompt.

This statement may be more accurate if want their exact age:

SELECT
firstnme,
midinit,
lastname,
birthdate,
year(current date - birthdate) as age
FROM employee
WHERE year(current date - birthdate) >= 65;
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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