Link to home
Start Free TrialLog in
Avatar of johnnyg123
johnnyg123Flag for United States of America

asked on

sql user Function to get list of values

Here is some sample data from my table named campaignoffers
(the fields are True or False to indicate whether an offer is valid for a given campaign)

campaignid      FreeCash          Points          GiftCard      Food      

236                         F                            F                F               F      
244                        T                            F                 F               F
249                        F                           T                     T              F      

I would like to write a function that will look at the individual flags and return a comma separated list of valid offers
(taking in campaign id as input parameter)

There should be at least one flag set to T for each campaign but if for some reason there isn't I want the function to return the string
'No Valid Offers'

Given the sample data above, I would like it to return the following

  'No Valid Offers' ( for campaign id  236)

'Free cash' ( for campaign id  244)

'Points, Gift Card'  ( for campaign id  249)
SOLUTION
Avatar of Nakul Vachhrajani
Nakul Vachhrajani
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnnyg123

ASKER

Thanks so much for the responses!

I elected to go with scott's solution because of the performance and cleaner approach

I did want to give Nakul some points for taking the time to post a working solution as well