0

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 ?

user3030035
  • 143
  • 1
  • 8

2 Answers2

0

Try this..

DECLARE @COMMA VARCHAR(MAX)
 SET @COMMA =''
 SELECT @COMMA =@COMMA +name+',' FROM yourtablename
 SELECT SUBSTRING(@COMMA,0,LEN(@COMMA))
Sunil Naudiyal
  • 334
  • 1
  • 13
0
    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.
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Avrajit
  • 230
  • 1
  • 2
  • 8
  • Variable declaration is not supported in SQL CE, So this method will not work with SQL CE. Unfortunately this is not answering my qustion. – user3030035 Dec 06 '13 at 07:46