asked on
Pivot Single Column with multiple values
This is just a general question, in SQL can you pivot based on multiple values, separated by commas in one column?
ex:
Column Name is Recodes and the values could be (PWID,CPWL,ADW) i know those are the only possible values, so could i make those as pivoted columns and flag 1 or 0 ?
Please post from sample data and the expected results.
I understand PIVOT.
I don't understand what you want to do with 'PWID,CPWL,ADW' and a 0/1 flag.
Please not description or images. Post typed/pasted text showing what you have and what you want.
ASKER
I apologize I don't know how to show the data in fiddle in the final format I need it. I'll try do now
ASKER
Ok, i built this fiddle
http://sqlfiddle.com/#!18/7e32f/1
the column charge recode can have a value of PWID, ADW or CPWL
The outcome that i'm looking for is the columns in the table there, plus pivitoted columns PWID, ADW and CPWL
Sometimes an arrest will have more than one in the column charge recode. I would like to pivot and mark 1 if the arrest number has one of those values, or 0 if now. I don't care about the null values.
I don't see where I asked for a fiddle.
I asked for example data and desired results.
What I'm looking for is a simple example of the data you have and the result from that data that you want.
Type it in here.
For example:
I have a columns called col1,col2,col3 with a values of:
'xxx','PWID,CPWL,ADW',9999
I need SQL to covert it into:
<type your results here>
Are you posting sensitive data on a public website?
The data in this question and your previous one looks like real data that might be sensitive in nature.
ASKER
ASKER
Thank you all!
I'd like to split the solution, I hope I can do that.
Yes, you can do that rather easily.