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 |
macca
Posting Yak Master
146 Posts |
Posted - 2012-01-13 : 10:54:34
|
I have a table called tblStart that contains 100's records. I want to run the following code on all records of tblStart:IF DateAppealed != NULL AND DateUnAppealed = NULLBEGINUPDATE tblStart SET John_Total_Days_On_Appeal = DATEDIFF(dd, DateAppealed, GETDATE())ENDELSEBEGINUPDATE tblStartSET John_Total_Days_On_Appeal = DATEDIFF(dd, DateAppealed, DateUnAppealed)ENDI keep getting the error that DateAppealed and DateUnAppealed ar unrecognised columns.Anyone know what I should do?Thanks. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-01-13 : 11:03:37
|
[code]UPDATE tblStartSET John_Total_Days_On_Appeal = CASE WHEN DateAppealed IS NOT NULL AND DateUnAppealed IS NULL THEN DATEDIFF(dd, DateAppealed, GETDATE()) ELSE DATEDIFF(dd, DateAppealed, DateUnAppealed) END[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-13 : 11:34:09
|
[code]UPDATE tblStartSET John_Total_Days_On_Appeal =DATEDIFF(dd, DateAppealed,COALESCE(DateUnAppealed,GETDATE()))[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
macca
Posting Yak Master
146 Posts |
Posted - 2012-01-17 : 04:12:53
|
Thanks guys, that worked. |
 |
|
|
|
|
|
|