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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-11-23 : 08:36:54
|
| Dan writes "hiI have a table with columns 1-12 one for each month.what I need to do is update the correct column agording to the the current month. I have tried using month(getdate())to call the column name and that did not work.I also changed the name of the column to Nov and tried the code below and still no success.declare @monthcol SMALlDATETIMEset @monthcol = convert(char(3),getdate())update new315_itvset @monthcol = new315_itv.eventdt from new315_itvwhere new315_itv.eventdt >= '09/01/2004'I know it can be done I am sure how to go about doing itThanks Dan" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-11-23 : 08:49:23
|
| The correct answer is to normalise your design then you won't have this problem.Other than thatdeclare @sql varchar(1000)select @sql = 'update new315_itvset ' + @monthcol + ' = new315_itv.eventdt from new315_itvwhere new315_itv.eventdt >= ''09/01/2004'''exec (@sql)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|