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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert Date

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2014-11-27 : 10:31:25
Hi,

I have the following query;


SELECT TOP (100) PERCENT dbo.EmisPatient.PatientID, dbo.EmisPatient.BirthYear, dbo.EmisPatient.Registered
FROM dbo.EmisPatient
ORDER BY dbo.EmisPatient.PatientID



Results


PatientID BirthYear Registered
1 1992-01-01 Y
2 1971-01-01 Y
3 1953-01-01 Y


What I would like to have as output at run time are 2 results;

RESULT 1

PatientID BirthYear Registered
1 01/01/1992 Y
2 01/01/1971 Y
3 01/01/1953 Y



RESULT 2

PatientID BirthYear Registered
1 1992 Y
2 1971 Y
3 1953 Y



Any help please..

Thanks

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-27 : 11:16:42
what is the datatype of the column BirthYear?
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2014-11-28 : 05:17:56
The datatype is (date, not null)

Thanks
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2014-11-28 : 05:42:57
RESULT 2: Achieved by


Left(dbo.EmisPatient.BirthYear, 4) As BirthYear,


I am not looking for the RESULT 1 hopefully someone will shade some light

Thanks
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-28 : 08:38:54
If BirthYear is type date, then year(birthYear) should work e.g.


declare @d date = getdate()
select year(@d)
Go to Top of Page
   

- Advertisement -