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
 Transact-SQL (2000)
 Case inside begin...End

Author  Topic 

elsietina
Starting Member

12 Posts

Posted - 2002-05-16 : 13:02:33
begin
if @counter=2
update t_import_main set program2=@prog, g2=@gno,yr2=@yr, Program_code2=@pcode where uno=@oldu
case
when @pcode is null then
Program_code2=@gno
End

I get this error message
Incorrect syntax near the keyword 'case'.
What am i doing wrong??

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-16 : 13:14:09
no biggie, small syntaxt error.
you've done the case statement after the where clause... I moved things around... you want the case statement after when you set programcode2

try

update t_import_main
set program2=@prog,
g2=@gno,yr2=@yr,
Program_code2=
case
when @pcode is null then @gno
else @pcode,
End
where uno=@oldu


what you want for the case statement will be

set column case
when @var is null then @diffvar
else @var
end


Go to Top of Page

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-05-16 : 13:14:50
DECLARE @program2 datatype
if len(@pcode) > 0
BEGIN
SET @program2 = @pcode
END
ELSE
BEGIN
SET @program2 = @prog
END

if @counter=2
update t_import_main set program2=@program2, g2=@gno,yr2=@yr, Program_code2=@pcode where uno=@oldu

Jeremy

sniped by M.E.
His suggestions looks better anyway!

Just curious if this would work instead?

Program_code2= IsNull(@pcode, @gno)

Edited by - joldham on 05/16/2002 13:16:13

Edited by - joldham on 05/16/2002 13:18:04
Go to Top of Page

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-16 : 13:24:42
wohoo.. my first sniping

Go to Top of Page

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-05-16 : 13:26:39
M.E.

I also was wondering Just if this would work instead?

Program_code2= IsNull(@pcode, @gno)

Jeremy

Go to Top of Page

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-16 : 13:32:02
I know.. I saw the question but couldn't answer it so I tried my best to avoid answering it ;)

lemme look it up.. Robvolk has given me some new insight on this function and it's uses

and from what I see... yes.. yes it would work.

Go to Top of Page

elsietina
Starting Member

12 Posts

Posted - 2002-05-16 : 13:48:09
Thanks


quote:

no biggie, small syntaxt error.
you've done the case statement after the where clause... I moved things around... you want the case statement after when you set programcode2

try

update t_import_main
set program2=@prog,
g2=@gno,yr2=@yr,
Program_code2=
case
when @pcode is null then @gno
else @pcode,
End
where uno=@oldu


what you want for the case statement will be

set column case
when @var is null then @diffvar
else @var
end






Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2002-05-20 : 22:17:31
Just for variety, COALESCE could do this too. But for only two choices, ISNULL is more sensible.

Sarah Berger MCSD
Go to Top of Page
   

- Advertisement -