Sql Query Help

Reply

Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

Sql Query Help

 
0
  #1
Nov 6th, 2006
Hello,

I am developing a simple calender in my site which will display the next upcoming birthday of my member.

I have a table which has 2 column


cname | dob
-------------------
Joe | 9/12/1982
Mathew | 2/17/1997
Pat | 8/23/1880
-------------------

What SQL Query should I use to get the name of that person?
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 32
Reputation: sierrasoft is an unknown quantity at this point 
Solved Threads: 0
sierrasoft sierrasoft is offline Offline
Light Poster

Re: Sql Query Help

 
0
  #2
Nov 7th, 2006
Hi, i think the following should help / give you an idea (eg retrieves names of members whose dob falls in current month--according to system date)

select cname from tablename wherE
datepart (mm,convert(datetime,dob))
= (select datepart(mm,convert(datetime,getdate())) )
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

Re: Sql Query Help

 
0
  #3
Nov 7th, 2006
Thanx but it generates this error

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error. in query expression 'datepart (mm,convert(datetime,dob)) = (select datepart(mm,convert(datetime,getdate())))'
Last edited by cancer10; Nov 7th, 2006 at 11:23 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 32
Reputation: sierrasoft is an unknown quantity at this point 
Solved Threads: 0
sierrasoft sierrasoft is offline Offline
Light Poster

Re: Sql Query Help

 
0
  #4
Nov 7th, 2006
Are you using Access and Jet?
Datepart will not work--it works only with SQL Server
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

Re: Sql Query Help

 
0
  #5
Nov 8th, 2006
Yes I am using Access and Jet

Any other solution?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Sql Query Help

 
0
  #6
Dec 8th, 2006
Originally Posted by cancer10 View Post
Yes I am using Access and Jet

Any other solution?
suppliment his solution a little. what language are you using to build the database. you may be suited to just use that language to get the current date and then pass that into the query.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3730 | Replies: 5
Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC