954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sql Query Help

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?

cancer10
Posting Whiz in Training
234 posts since Dec 2004
Reputation Points: 58
Solved Threads: 1
 

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())) )

sierrasoft
Light Poster
31 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

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())))'

cancer10
Posting Whiz in Training
234 posts since Dec 2004
Reputation Points: 58
Solved Threads: 1
 

Are you using Access and Jet?
Datepart will not work--it works only with SQL Server

sierrasoft
Light Poster
31 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

Yes I am using Access and Jet

Any other solution?

cancer10
Posting Whiz in Training
234 posts since Dec 2004
Reputation Points: 58
Solved Threads: 1
 
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.

Killer_Typo
Master Poster
781 posts since Apr 2004
Reputation Points: 152
Solved Threads: 39
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You