cancel
Showing results for 
Search instead for 
Did you mean: 

sql case statement for parametes

Former Member
0 Kudos

I am using sort parameters in the stored procedure

the following is my case statment

CASE When @SORT_1 = 'CUSTOMER'

Then ar_ivhdr_tbl.EN_CUST_KEY

When @SORT_1 = 'BILLTO'

Then ar_bill_tbl.ar_bill_name

Else ' ' END SORTKEY

what i would like to do is

have the sort key sort by 2 fields so instead of just the customer sort sorting the customer field

i would like it to sort customer and bill to

this is the syntax i tried but sql doesnt like it

CASE When @SORT_1 = 'CUSTOMER'

Then ar_ivhdr_tbl.EN_CUST_KEY,ar_bill_tbl.ar_bill_key

When @SORT_1 = 'BILLTO'

Then ar_bill_tbl.ar_bill_name, date

Else ' ' END SORTKEY

syntax issues, any ideas?

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member292966
Active Contributor
0 Kudos

Hi Sharon,

Your syntax is off. Not sure what database you are using by it should look something like:

CASE @SORT_1
When 'CUSTOMER' Then ar_ivhdr_tbl.EN_CUST_KEY,ar_bill_tbl.ar_bill_key
When 'BILLTO' Then ar_bill_tbl.ar_bill_name, date
Else ' ' 
END

Good luck,

Brian