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.
Author |
Topic |
sunny_10
Yak Posting Veteran
72 Posts |
Posted - 2014-11-09 : 10:10:02
|
HiI 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 fieldTable name is Test.Thanks |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-11-10 : 09:22:40
|
update tableset date = dateadd(day, 1-day(getdate()) ,getdate()) |
|
|
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 mentionedThanks |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-11-10 : 09:37:38
|
DECLARE @monthfield int = 7DECLARE @yearfield int = 2014SELECT dateadd(month, @monthfield-1, dateadd(year, @yearfield-1900, 0)) |
|
|
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 |
|
|
|
|
|