SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 converting date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rayman
Starting Member

USA
39 Posts

Posted - 11/09/2010 :  16:59:27  Show Profile  Reply with Quote
I read the earlier post to see if someone had address this topic.
I have a column with the following data:

birth_date
4/23/1945
8/20/1962
3/27/1962
2/11/1958
3/21/1951
11/18/1951
8/15/1983
2/22/1971
1/24/1931
11/14/1944
12/15/1949
10/15/1965
9/25/1967
I need to read this and produce the following information:

day_born/age
Monday / 41.7
Wednsday/ 58.2
Saturday/ 78.4
Tuesday / 51.3
Sunday / 57.6
Thursday/ 59.5
Monday / 64.1
Friday / 43.6
Tuesday / 64.6
I placed the forward slash in the represent the space between the data and column.
But I need to calculate the date and extract the day of the week and the years


Terry Lynn King

tkizer
Almighty SQL Goddess

USA
36942 Posts

Posted - 11/09/2010 :  17:15:35  Show Profile  Visit tkizer's Homepage  Reply with Quote
Search the forums and Internet for various age functions. There are many. To figure out day_born, use DATENAME function with birth_date.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Rayman
Starting Member

USA
39 Posts

Posted - 11/10/2010 :  12:36:19  Show Profile  Reply with Quote
SELECT person_name, birth_city,
dayname(birth_date) as day_born,
truncate(datediff(current_date,birth_date)/ 365,1) as age,
operations
FROM `john`
ORDER by person_name

The query is hanging on the dayname function. Is there a better way to do this? I reviewed the Microsoft SQL server transact-SQL and utilities reference, Vol 2. I am just missing a simple syntax issue.
The error states dayname not a recognize function. I change to Day and get the same thing.

Terry Lynn King
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36942 Posts

Posted - 11/10/2010 :  12:38:54  Show Profile  Visit tkizer's Homepage  Reply with Quote
This doesn't look like Microsoft SQL Server. What dbms are you using?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Rayman
Starting Member

USA
39 Posts

Posted - 11/10/2010 :  13:00:01  Show Profile  Reply with Quote
Microsoft SQL 2005 on Windows 2003 server.

Terry Lynn King
Go to Top of Page

TimSman
Posting Yak Master

USA
127 Posts

Posted - 11/10/2010 :  13:05:28  Show Profile  Reply with Quote
There is no DayName function. Unless you wrote it.

And why do you have TRUNCATE in there? I would get rid of that, too.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 11/11/2010 :  04:58:30  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
TRUNCATE is an ORACLE function. Also there is no reason to use it on the numbers as datediff will return integers

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000