Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 table student and matrix

in student table columns are-

studentid studentname
1001 ashish
1002 shiva
1003 hasan
1004 hina


and in matrix table columns are-

seatno studentid
1 1001
2 1002
3 1003
4 1004


i want to print 2 column value in a single column using sql query like

student

1,ashish
2,shiva
3,hasan
4,hina
Posted

try this one...
SQL
Select
cast(seatno as varchar) + ',' + Studentname
from StudentTable s
inner join MatrixTable m on m.Studentid = s.studentID
 
Share this answer
 
SQL
castSeatnno to varchar 
 That should work

Select
cast(seatno as varchar(10)) + ',' + Studentname
from StudentTable s
inner join MatrixTable m on m.Studentid = s.studentID
 
Share this answer
 
Comments
TCS54321 11-Apr-14 9:16am    
its working... thanku
hey you could use this query

Select
seatno + ',' + Studentname
from StudentTable s
inner join MatrixTable m on m.Studentid = s.studentID
 
Share this answer
 
Comments
TCS54321 11-Apr-14 9:05am    
Conversion failed when converting the varchar value ',' to data type int.

this is a error when i run this query
SQL
select convert(varchar, seatno) + ',' + studentname
from student s join matrix m on
s.studentid = m.studentid
 
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