简体   繁体   中英

SQL code (SSRS 2008 version)

I need to write the following in SQL:

I have a table that has 2 columns that I am interested in (ID, Text field). Each ID could have a few values in the text field.

ID   TEXT
1   value1
1   value2
2   value1
2   value2
2   value4

I need to create a report that list the following

ID     value1        value2       value3        value4         etc.  
1        yes          yes
2        yes          yes                        yes

thank you

SELECT 
   ID, 
   Value1 = MAX(case WHEN [Text] = 'Value1' THEN 'yes' ELSE '' END),
   Value2 = MAX(case when [Text] = 'Value2' THEN 'yes' ELSE '' END),
   Value3 = MAX(case when [Text] = 'Value3' Then 'yes' ELSE '' END)
GROUP BY
   ID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM