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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQl statement

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 tmf
set unita=1

Go
update tmf
set unitb=2.2
where 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 them

update tmf
set unita=1

update tmf
set unitb=2.2
where qtyb is not null

will do
you could do it in one

update 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.
Go to Top of Page

mbevon
Starting Member

41 Posts

Posted - 2002-09-26 : 14:35:52

What do you mean by separate batches?

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-09-26 : 14:53:25
disunite, differentiate, discriminate between, distinguish one batch from another

Jay White
{0}
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2002-09-27 : 04:02:02
quote:

you could do it in one

update 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 null

but the original was

...when qtyb is not null then 2.2

I 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 end

which would be more like the original.

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-09-27 : 06:44:24
mr_mist

update 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.2

In 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.
Go to Top of Page

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.

Go to Top of Page
   

- Advertisement -