Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

In my database there are seven columns with the value "Y" and "N". I want to take the "Column Heading" Which the values are "Y" and I want to Concatenate it with Comma. Can any one help me to solve this problem. My requirement is like this:


Column Header: TE HE FE RE YE WE DS
Column Values: Y N N Y N Y Y
N N N N Y N N


OutPut Should be Like this:


for First Row: TE,RE,WE,DS
for Second Row: YE


Thanks in Advance
Posted
Comments
Sergey Alexandrovich Kryukov 3-Apr-12 2:51am    
What did you try so far?
--SA

I would do something like this:

SQL
select case 
       when len([ekeke]) > 0 then (left([ekeke], len(ekeke) - 1)) 
       else [ekeke] 
       end /* case */ as 'ekeke'
from 
(
    select 
        case when [TE]='Y' then 'te,' else '' end + 
        case when [HE]='Y' then 'he,' else '' end + 
        case when [FE]='Y' then 'fe,' else '' end + 
        case when [RE]='Y' then 're,' else '' end + 
        -- ... more lines here ...
        case when [DS]='Y' then 'ds,' else '' end 
        as 'ekeke'
) v


Hope this helps,
Pablo.
 
Share this answer
 
Select TE +','+RE+','+WE+','+DS from your_table
union 
SElect YE from your_table 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900