Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Case Help

Status
Not open for further replies.

strom99

MIS
Nov 28, 2000
126
US
I have the following case statement getting the following error

Server: Msg 156, Level 15, State 1, Line 17
Incorrect syntax near the keyword 'else'.

Any ideas? Thanks Much


case when detail.rec_stus_id = '1' then
case when bg.bus_grp_id = 1 and demand.mfg_fclt_code in ('cg','ci','ac') then
case when (m.invt_cost = 0 or m.invt_cost is null) then (gs.sllr_figqy_conv_fc * detail.shpd_qty)
else (gs.sllr_figqy_conv_fc * detail.shpd_qty) * (m.invt_cost)
end
end
end
else
case when detail.rec_stus_id <> '1' then
case when bg.bus_grp_id = 1 and demand.mfg_fclt_code in ('cg','ci','ac') then
case when (m.invt_cost = 0 or m.invt_cost is null) then (gs.sllr_figqy_conv_fc * detail.ord_qty)
else (gs.sllr_figqy_conv_fc * detail.ord_qty) * (m.invt_cost)
end
end
end
 
Hi,

Instead of CASE use if and there is no THEN keyword in T-SQL...

syntax is like this

IF Condition
Begin
Code goes here..........
End
Else
Begin
if Condition
Begin
Code goes here...........
End
End
 
You have your end in the wrong place. Try this:


case when detail.rec_stus_id = '1' then
case when bg.bus_grp_id = 1 and demand.mfg_fclt_code in ('cg','ci','ac') then
case when (m.invt_cost = 0 or m.invt_cost is null) then
(gs.sllr_figqy_conv_fc * detail.shpd_qty)
else (gs.sllr_figqy_conv_fc * detail.shpd_qty) * (m.invt_cost)
end
end
else
case when detail.rec_stus_id <> '1' then
case when bg.bus_grp_id = 1 and demand.mfg_fclt_code in ('cg','ci','ac') then
case when (m.invt_cost = 0 or m.invt_cost is null) then
(gs.sllr_figqy_conv_fc * detail.ord_qty)
else (gs.sllr_figqy_conv_fc * detail.ord_qty) * (m.invt_cost)
end
end
end
end


Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top