Click here to Skip to main content
15,918,193 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 Subject:

No. | CourseCode| subject |

1 | Cur001| English|
2 | Cur001| math|
3 | Cur001| Hindi|

Data I would like to display in my GridView GridView1:

No. | CourseCode| subject |

1 | Cur001 | English, math, Hindi|

how i write "SELECT" Command for this in sql2008 and C# code for GrideView
Posted
Comments
Bernhard Hiller 30-Jan-14 2:58am    
I do not understand where that "1" for "No." in the result is expected to come from - the Subject table has several different values.
By the way, your tags include C# - so why don't you do that in C# after getting the rows from the table to your program?

do not repost questions.
you already asked simillar question here ^[^]

as per basmeh Awad answer:-
select no,username,role1 +','+role2+','+role3 as ROLE from UserData

in case you need to combin 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
 
Share this answer
 
Thanks All
i have Solve my Problem
 
Share this answer
 
 
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