sql case statement error

I have a case statement in my sql

case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS] else (case when([SSP] Is Not Null And [ST]='y' then [PT]*[TSS] else 0) end AS STT,

I am getting an error reading:

Incorrect syntax near the keyword 'then'.

I have tried to fix it but i am not sure what the problem is
Mr_ShawAsked:
Who is Participating?
 
momi_sabagCommented:
try

case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS]
else case when([SSP] Is Not Null And [ST]='y' then [PT]*[TSS] else 0 end end AS STT
0
 
chapmandewCommented:
case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS] else (case when([SSP] Is Not Null And [ST]='y' then [PT]*[TSS] else 0 end) end AS STT,
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you are missing the second END:

case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS] else (case when([SSP] Is Not Null And [ST]='y' then [PT]*[TSS] else 0 end) end AS STT,

however, you can "simplify":

case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS] when([SSP] Is Not Null And [ST]='y' then [PT]*[TSS] else 0 end AS STT,
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Daniel WilsonCommented:
You are missing an END ... also a ) ... which  I think is what's raising that message.

case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS] else (case when([SSP] Is Not Null And [ST]='y') then [PT]*[TSS] else 0 end) end AS STT,

Open in new window

0
 
reb73Commented:
You don't a nested case statement -

Try -
CASE	when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS]
	when [SSP] Is Not Null And [ST]='y' then [PT]*[TSS]
	else 0
END AS STT

Open in new window

0
 
Mr_ShawAuthor Commented:
i tried

case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS] when([SSP] Is Not Null And [ST]='y' then [PT]*[TSS] else 0 end AS STT,

but still got an error
0
 
chapmandewCommented:
you didn't copy what I gave you....
case when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS] else (case when([SSP] Is Not Null And [ST]='y' then [PT]*[TSS] else 0 end) end AS STT,
0
 
Mr_ShawAuthor Commented:
The following cleared the error

CASE      when [SSS] In ('34','33') And [ST]='y' then [TT]*[TS]
      when [SSP] Is Not Null And [ST]='y' then [PT]*[TSS]
      else 0
END AS STT
0
 
Daniel WilsonCommented:
You don't need that ( between WHEN and [SSP] is NOT NULL

but if you do have the (, match it with a )
0
 
Mr_ShawAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.