![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, can I do this via SQL: example: tbltest has 5 rows: col1 === A C F M R What I want is this: result: =============== A, C, F, M, R Do I really have to go through the rows per SP? I could do this: |
#3
| |||
| |||
|
| It helps you in situaions whenever you wish to create commm seperated |
#4
| |||
| |||
|
|
Well, I knew I had read something about it but where? NOW I found it, maybe from sqlservercentral.com, don't know the author, but it works and is a straight solution. thx for your answers candide_sh It helps you in situaions whenever you wish to create commm seperated values actually originating from multiple records. Say, your query return three records in folloing patter: Student_Name ============= Ricky Adam Mathew But, say you wish to have records in following patter: Student_Name ============ Ricky, Adam, Mathew That is how it works. Try it...I beleive it will help you a lot create procedure sp_return_students as set nocount off /* Declare variable which will store all student name */ Declare @StudentName varchar(8000) /* Query that will return student names and at the same time concatenate values. /* select @StudentName = coalesce(@StudentName + ', ', '') + stu_name from tbl_students /* At last, you just have to define column name that will store values */ Select @StudentName As Student_Name |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
The kludges that have been posted are unpredictable, unsupported and some are highly proprietary. |
#7
| |||
| |||
|
|
Get a job in the real world; do us all a favour; your comments are novice at best. |
#8
| |||
| |||
|
|
The kludges that have been posted are unpredictable, unsupported and some are highly proprietary. Let's make it clear, the use of text() and FOR XML is supported and fully documented in books online, it is not a kludge; |
#9
| |||
| |||
|
#10
| |||
| |||
|
|
Nah, I think text() + FOR XML certainly has the flavour of a kludge over it. The syntax is anything about intuitive, and if the data include ampersands or angle brackets, there are a few surprising waiting for us. |
![]() |
| Thread Tools | |
| Display Modes | |
| |