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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Extract day portion of date field

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-10-20 : 09:06:26
I have a table:

date name dayofmonth
---- ---- ----------

20090802 Smith
20080716 Reynolds
20080622 Collins

I need to update the newly added column 'dayofmonth' (int) to be the same as the day portion of the date field to give


date name dayofmonth
---- ---- ----------

20090802 Smith 2
20080716 Reynolds 16
20080622 Collins 22

How can I do this please?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-10-20 : 09:10:25
SELECT date,name,[dayofmonth] = DATEPART(day,date)
FROM
yourTable

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-10-20 : 09:44:38
Many thanks Jim
Go to Top of Page
   

- Advertisement -