how to build a Comma seperated list from a table in SQL CE ?
I have table named Group and it has two columns ID and Name
I want to select a one comma seperated string from Group table.
So IF I have 3 records as follows in group table
ID | Name
1 | Msh
2 | Nsh
3 | Lsh
I want to get a one comma seperated list of all three names like this Msh,Nsh,Lsh
How can I get this done is SQL CE
?
Try this..
DECLARE @COMMA VARCHAR(MAX)
SET @COMMA =''
SELECT @COMMA =@COMMA +name+',' FROM yourtablename
SELECT SUBSTRING(@COMMA,0,LEN(@COMMA))
You can develop a simple logic in SQL. This is a dummy code you can try and modify the code as per your requirements.
declare
i varchar2(100);
j varchar2(100);
begin
for i in (select name from avrajit)
loop
j:=i.name||','||j;
end loop;
dbms_output.put_line(j);
end;
---------------------------------------
OUTPUT
---------------------------------------
Hitesh,Sushil2,Mukul,Shyam,Nikheel,Avrajit,Sushil,
Statement processed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.