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 |
|
elsietina
Starting Member
12 Posts |
Posted - 2002-05-16 : 13:02:33
|
| beginif @counter=2update t_import_main set program2=@prog, g2=@gno,yr2=@yr, Program_code2=@pcode where uno=@olducase when @pcode is null thenProgram_code2=@gnoEndI 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 programcode2try update t_import_main set program2=@prog, g2=@gno,yr2=@yr, Program_code2=casewhen @pcode is null then @gnoelse @pcode,End where uno=@oldu what you want for the case statement will beset column casewhen @var is null then @diffvarelse @varend |
 |
|
|
joldham
Wiseass Yak Posting Master
300 Posts |
Posted - 2002-05-16 : 13:14:50
|
DECLARE @program2 datatypeif len(@pcode) > 0BEGIN SET @program2 = @pcodeENDELSEBEGIN SET @program2 = @progENDif @counter=2update t_import_main set program2=@program2, g2=@gno,yr2=@yr, Program_code2=@pcode where uno=@oldu Jeremysniped 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:13Edited by - joldham on 05/16/2002 13:18:04 |
 |
|
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-05-16 : 13:24:42
|
wohoo.. my first sniping |
 |
|
|
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 |
 |
|
|
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 usesand from what I see... yes.. yes it would work. |
 |
|
|
elsietina
Starting Member
12 Posts |
Posted - 2002-05-16 : 13:48:09
|
Thanksquote: 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 programcode2try update t_import_main set program2=@prog, g2=@gno,yr2=@yr, Program_code2=casewhen @pcode is null then @gnoelse @pcode,End where uno=@oldu what you want for the case statement will beset column casewhen @var is null then @diffvarelse @varend
|
 |
|
|
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 |
 |
|
|
|
|
|
|
|