Click here to Skip to main content
14,695,098 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using VS2008 C# and SQL2008 R2.

I would like to retrieve data from multiple columns and merge them, separating them by comma.

E.g. Data in my SQL Table UserData:

No. | Username | Role 1 | Role 2 | Role 3 |

1 | firoz| USER | READONLY | WRITE |

Data I would like to display in my GridView GridView1:

No. | Username | Roles |

1 | firoz| USER, READONLY, WRITE |

how i write "SELECT" Command for this in sql2008 and C# code for GrideView
Posted

1 solution

try this
select no,username,role1 +','+role2+','+role3 as ROLE from UserData

in case you need to combine a numeric data type with varchar datatype then you need to use this
select no,username,cast(no as varchar)+','+role1 +','+role2+','+role3 as ROLE from UserData
   
v3
Comments
TrushnaK 30-Jan-14 2:30am
   
nice ans my 5+..
Basmeh Awad 30-Jan-14 3:07am
   
thanks Trushnak

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