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 |
|
mbevon
Starting Member
41 Posts |
Posted - 2002-09-26 : 14:08:05
|
| How do i do an sql with three different statement to run one after the other?Is it like this (below) this?Go update tmfset unita=1Goupdate tmfset unitb=2.2where qtyb is not null |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-09-26 : 14:26:51
|
| Well you've only two statements there.The go's will separate batches and you probably don't need themupdate tmf set unita=1 update tmf set unitb=2.2 where qtyb is not null will doyou could do it in oneupdate tmf set unita=1 ,unitb=case when unitb is null then null else 2.2 end You also might want to look at transactions and error handlingt if you want it to be atomic.==========================================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. |
 |
|
|
mbevon
Starting Member
41 Posts |
Posted - 2002-09-26 : 14:35:52
|
| What do you mean by separate batches? |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-09-26 : 14:53:25
|
| disunite, differentiate, discriminate between, distinguish one batch from anotherJay White{0} |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2002-09-27 : 04:02:02
|
quote: you could do it in oneupdate tmf set unita=1 ,unitb=case when unitb is null then null else 2.2 end
That's slightly different from what the original poster had in mind though I think.You've got when unitb is null then nullbut the original was...when qtyb is not null then 2.2I imagine it was probably a typo.I don't know if you can do :update tmf set unita = 1, unitb = case when qtyb is not null then 2.2 else unitb endwhich would be more like the original. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-09-27 : 06:44:24
|
| mr_mistupdate tmf set unita=1 , unitb=case when unitb is null then null else 2.2 end if unitb is then it leaves it as null.if unitb is not null then it sets it to 2.2In fact does the same as yours which will work too - you've just done the test on not null instead of null and swapped the operations round.==========================================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. |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2002-09-27 : 06:53:06
|
| The difference is that the original poster asked about changing unitb when qtyb is not null, and your answer was based on unitb itself being not null. Unless I am missing something here. |
 |
|
|
|
|
|