Age Calculation duplicate column using sql server 2008 R2 -



Age Calculation duplicate column using sql server 2008 R2 -

i have login table dob column. need duplicate column age. can't this. can convert dob column convert age lone

`select floor(datediff(day,'10/10/1990' , getdate()) / 365.25)` works fine.

but need convert whole column.

if i'm using

select floor(datediff(day,select dob login_tbl , getdate()) / 365.25) this,

it's throwing error. how can it?

thankyou

your approach wrong result in such cases below:

declare @now date set @now = '11/10/2014' select floor(datediff(day,'11/10/2013' , @now) / 365.25) -- should 1 0 , floor(datediff(day,'11/10/2012' , @now) / 365.25) -- should 2 1 , datediff(day,'11/10/2013' , @now) , datediff(day,'11/10/2012' , @now)

my suggestion :

declare @now date set @now = '11/10/2014' select (convert(int,convert(varchar(8), @now ,112)) - convert(int,convert(varchar(8),convert(date,'11/10/2013'),112) ) )/10000

you see explain in this answer.

so login_tbl could:

select dob, (convert(int,convert(varchar(8), dob ,112)) - convert(int,convert(varchar(8),convert(date,'11/10/2013'),112) ) )/10000 age login_tbl

sql-server-2008

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -