Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SQL Expression Field - Combine Declared Variable With Case Statement

Hello All, I have been using Crystal & Business Objects for a few months now and have figured out quite a bit on my own. This is the first real time I have struggled with something and while I could do this as a Formula Field I would like to know how to do this as a SQL Expression. Basically I want to create a SQL Expression that uses a CASE statement but I wanted to make the code a little more efficient and employ a variable to hold a string and then use the variable in the CASE statement. The expression editor accepts the CASE statement OK but I don't know how to declare the variable. Please assist with the syntax?

This is what I have:

CASE

WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Hu2019 THEN u2018Hedgeu2019

WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Pu2019 THEN u2018PVIu2019

ELSE u2018Noneu2019

END

This is what I want:

DECLARE strVar AS VARCHAR(25)

strVar = u201CDatabaseu201D.u201DFieldu201D

CASE

WHEN strVar = u2018Hu2019 THEN u2018Hedgeu2019

WHEN strVar = u2018Pu2019 THEN u2018PVIu2019

ELSE u2018Noneu2019

END

Not what you were looking for? View more on this topic or Ask a question