Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

CASE statement SQL (using IN )

I am trying to identify an individual based on codes in our database. I need to assign a name to a person based on what the individuals codes are for that year. Donations.

I am trying to use an in statement in a case statement.. I can't seem to find any information on this being possible or not out there. It is not looking good though :(.

Escencially, what I need to find out is by grouping by donor and looking at all of the donors records. if they have given specific procedures..

Please see the code and I will be happy to explain in more detail what I am trying to do if you are confused..
select donor_id, donation_procedure,
CASE donation_procedure
WHEN donation_procedure IN ('PL', 'PE', 'PR', 'PP', 'RP','DR', 'LV', 'WB', 'HH', 'AU', 'CU', 'SM', 'Q0', 'TH' THEN 'REDCELL' 
WHEN (donation_procedure IN ('PL', 'PE', 'PR', 'PP', 'PR')) AND (donation_procedure) NOT IN ('DR', 'LV', 'WB', 'HH', 'AU', 'CU', 'SM', 'Q0', 'TH')) THEN 'APHERESIS'
ELSE 'UNKNOWN' END
from TABLE_INFO
where  (collection_date >= DATEADD(day, - 365, GETDATE()))
group by donor_id, donation_procedure
order by donor_id

Open in new window

0
Jennifer Barman
Asked:
Jennifer Barman
1 Solution
 
Ephraim WangoyaCommented:
try like this
select donor_id, donation_procedure,
	CASE 
	WHEN ((donation_procedure IN ('PL', 'PE', 'PR', 'PP')) AND 
	      (donation_procedure) NOT IN ('DR', 'LV', 'WB', 'HH', 'AU', 'CU', 'SM', 'Q0', 'TH')) THEN 
		'APHERESIS'
	WHEN donation_procedure IN ('PL', 'PE', 'PR', 'PP', 'RP','DR', 'LV', 'WB', 'HH', 'AU', 'CU', 'SM', 'Q0', 'TH') THEN 
		'REDCELL' 	
	ELSE 
		'UNKNOWN' 
	END
from TABLE_INFO
where  (collection_date >= DATEADD(day, - 365, GETDATE()))
group by donor_id, donation_procedure
order by donor_id

Open in new window

0
 
Jennifer BarmanAuthor Commented:
THANKS!! :) worked perfectly! :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now