Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I need to return both values in the yyyy-mm-dd formatHere is I need to return: EM_HIRE_DATE or EM_REHIRE_DATE if exist(date on which emp started working).The Output returned only one value formated but not another.output:HIRE_DT20070627 1986-09-29Here is my script:SELECT em_hire_date, em_rehire_date,CASE WHEN em_rehire_date <> '' THEN em_rehire_date ELSERIGHT(CAST(YEAR(EM_HIRE_DATE) AS varchar(4)), 4)+ '-' +RIGHT(CAST(1000 + MONTH(EM_HIRE_DATE) AS varchar(5)), 2) + '-' + RIGHT(CAST(1000 + DAY(EM_HIRE_DATE) AS varchar(5)), 2) end as HIRE_DTFROM EMF
jdaman
Constraint Violating Yak Guru
354 Posts
Posted - 2008-05-14 : 15:21:14
Not sure which date format that you are asking for so I will give you both:
check out books on line... it come with SQL Server. Do a search under t-sql for "convert".It's a great resource and will give you a much faster answer.An infinite universe is the ultimate cartesian product.
dbacon
Starting Member
7 Posts
Posted - 2008-05-14 : 18:07:37
I got it from the books online. Thanks a lot.
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-05-17 : 09:10:08
1 Always use proper DATETIME datatype to store dates2 Let front end application do the formationMadhivananFailing to plan is Planning to fail