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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date issues in sqlserver 2000
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqldba2k6
Posting Yak Master

176 Posts

Posted - 06/14/2007 :  17:31:54  Show Profile  Reply with Quote
I have below data in a table

Table1:

MM DD YR
--- -- ----
5 4 2007

I need the below output like.

Date
----------
2006-05-26


Thanks for your help in advance

sqldba2k6
Posting Yak Master

176 Posts

Posted - 06/14/2007 :  17:35:17  Show Profile  Reply with Quote
Please ignore my previous post

Below is correct one

I have below data in a table

Table1:

MM DD YR
--- -- ----
5 4 2007

I need the below output like.

Date
----------
2007-05-04


Thanks for your help in advance
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4361 Posts

Posted - 06/14/2007 :  17:44:07  Show Profile  Reply with Quote
Here are two ways:
DECLARE @T TABLE (MM int, DD int, YR int)
INSERT @T
SELECT 5, 4, 2007	
	

SELECT 
	CAST(CAST(YR AS VARCHAR) + RIGHT('0' + CAST(MM AS VARCHAR), 2) + RIGHT('0' + CAST(DD AS VARCHAR), 2) AS DATETIME)
	,DATEADD(DAY, DD - 1, DATEADD(MONTH, MM - 1,DATEADD(YEAR, YR - 1900, 0)))
FROM @T
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 06/14/2007 :  17:47:44  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
Keep it simple:

http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx

- Jeff
http://weblogs.sqlteam.com/JeffS

Edited by - jsmith8858 on 06/14/2007 19:30:01
Go to Top of Page

sqldba2k6
Posting Yak Master

176 Posts

Posted - 06/14/2007 :  20:49:09  Show Profile  Reply with Quote
Thanks a lot
Go to Top of Page

johnsql
Posting Yak Master

USA
161 Posts

Posted - 11/12/2007 :  16:52:27  Show Profile  Reply with Quote
quote:
Originally posted by sqldba2k6

Please ignore my previous post

Below is correct one

I have below data in a table

Table1:

MM DD YR
--- -- ----
5 4 2007

I need the below output like.

Date
----------
2007-05-04


Thanks for your help in advance



Another way to do

select mm, dd, yr,  dateadd(day,dd-1,dateadd(month,mm-1,dateadd (year,yr-1900,0))) as DateInQuestion  
from @t
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29910 Posts

Posted - 11/12/2007 :  17:47:00  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT DATEADD(MONTH, YR * 12 - 22801 + MM, DD - 1)




E 12°55'05.25"
N 56°04'39.16"
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.08 seconds. Powered By: Snitz Forums 2000