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 |
|
smithani
Starting Member
42 Posts |
Posted - 2007-09-05 : 10:46:41
|
| Hi,I want to update the values of two collumns in a table with different data for the same condition , (plesea see below) Is there any other way of doing this without repeating the condition twice.declare @selected intset @selected = 2007update Process set season= case when year(nextdate) >@selected then year(nextdate) end,set program=case when year(nextdate) >@selected then nextdate endend |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-09-05 : 10:49:28
|
| DECLARE @TempVar intupdate Process set @TempVar = case when year(nextdate) >@selected THEN 1 ELSE 0 end,season= case when @TempVar = 1 then year(nextdate) end,set program=case when @TempVar = 1 then nextdate endend but it won't save much, if any, CPU time unless you have a more complicated algorithm. It might save a maintenance snafu in the future though ...Kristen |
 |
|
|
Koji Matsumura
Posting Yak Master
141 Posts |
Posted - 2007-09-05 : 20:57:13
|
| season and program will be NULL when year(nextdate) <= @selected.Why tow conditions are same? |
 |
|
|
Koji Matsumura
Posting Yak Master
141 Posts |
Posted - 2007-09-05 : 21:44:33
|
| sorry, misunderstood your questionUPDATE ProcessSET seson = YEAR(nextdate), program = nextdateWHERE YEAR(nextdate) > @selected |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-09-06 : 03:52:31
|
| Ah, Koji is probably right. I though you had just posted a snippet of your total code! |
 |
|
|
|
|
|