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
 SQL Server Administration (2005)
 Update Field

Author  Topic 

sunny_10
Yak Posting Veteran

72 Posts

Posted - 2014-11-09 : 10:10:02
Hi

I have 1 Table with fields Month & Year both are numeric. I have created another field Date , Data Type is Date . What should be the query to update Date field in all records.

If value in month field is 7 & value in year field is 2014 then i want 01/07/2014 in Date field


Table name is Test.

Thanks

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-10 : 09:22:40
update table
set date = dateadd(day, 1-day(getdate()) ,getdate())
Go to Top of Page

sunny_10
Yak Posting Veteran

72 Posts

Posted - 2014-11-10 : 09:26:43
Hi

I want month & year values from the 2 fields (Month & Year) , which you have not mentioned

Thanks
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-10 : 09:37:38
DECLARE @monthfield int = 7
DECLARE @yearfield int = 2014
SELECT dateadd(month, @monthfield-1, dateadd(year, @yearfield-1900, 0))
Go to Top of Page

sunny_10
Yak Posting Veteran

72 Posts

Posted - 2014-11-11 : 00:20:01
Hi Gbritton

I don't want to create variables . I have already 2 fields Month & Year in a table . I want to combine these 2 fields & update another field Dates which is if date Data Type. Day will always be 1 since i am not storing day in any field.

Thanks
Go to Top of Page
   

- Advertisement -