Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi all,I want to search a field from table and get a set of record.But I want to put all the records into a field.For example, I use the following sqlselect distinct(a) from tbl_a where ....and get the following result a=======appleangleabc123but I want to show the result as a=======apple,angle,abc123How to modify the sql and get the result?thanks
Note that you may face problems if concatenated string exceeds 8000 characters. If you use Front end application do the concatenation thereMadhivananFailing to plan is Planning to fail
KinYeung
Starting Member
14 Posts
Posted - 2006-06-29 : 00:16:41
Thanks allIs it possible to do this within a query. coz it's not allow me to create any function in the server (peoplesoft database)
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-06-29 : 00:26:18
quote:Originally posted by KinYeung Thanks allIs it possible to do this within a query. coz it's not allow me to create any function in the server (peoplesoft database)
Just use the technique in the link and create it in a store procedureKH
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-06-29 : 00:31:52
Here it is. No function required.
-- Prepare the table & data for testingdeclare @tbl_a table( a varchar(10))insert into @tbl_aselect 'apple' union allselect 'angle' union allselect 'abc123'-- Querydeclare @result varchar(8000)select @result = coalesce(@result + ',' + a, '' + a)from @tbl_aprint @result/* RESULTapple,angle,abc123*/