-3

I have 4 bit values and a varchar

sku
a
b
c
d

From a SELECT statement I need to get the following result for each bit value that has a value of 1.

So for each bit value I need to output its actual name, so the result would look like:

"NameOfSKU, a, c"

In a comma delimited format.

gbn
  • 422,506
  • 82
  • 585
  • 676
Bill
  • 1
  • 1
  • 2
    Please post the code you have written so far. People generally do not like to just write your code for you. As it is, this is a work description, not a question. – Mitch Wheat May 19 '11 at 14:01
  • 1
    Why/how do you get "a, c" for "NameOfSKU" ?? Not very clear..... can you try and elaborate a bit more?? – marc_s May 19 '11 at 14:01
  • It's a case *expression* not a statement – gbn May 19 '11 at 14:17

1 Answers1

1
SELECT sku 
     + (CASE WHEN a=1 THEN ', a' END)
     + (CASE WHEN b=1 THEN ', b' END)
     + (CASE WHEN c=1 THEN ', c' END)
     + (CASE WHEN d=1 THEN ', d' END)
FROM someTable
ShaneBlake
  • 11,056
  • 2
  • 26
  • 43