Nalza Nalza - 1 year ago 37
SQL Question

SQL Query/Linq : How to get data from mutiple column with specific criteria to feed to dropdownlist

|Distict | Gold | Silver | Bronze |
|B-------|0------ |Y-------|0---------|
|C-------|0------ |0-------|Y---------|

I want to bind a dropdownlist to a specific row based on the column that got Y in the field

i.e: if district A got all medal (noted with Y), the dropdownlist will get Gold, Silver and Bronze in the list items, else as in the example the dropdown wil have only gold and bronze.


You can do this by unpivoting the data

SELECT distict, 
FROM   yourtable 
       CROSS apply (VALUES ('Gold',gold), 
                           ('Bronze',bronze)) cs (NAME, value) 
WHERE  value = 'Y'