Tags

,


Return row data into comma separated format

Ex:
SNo        Department
1             Computer
2             Account
3             Sale
4             Post Sale
Return
[Computer], [Account], [Sale], [Post Sale],

Step 1:: Create Function

Create Function RowToSep(@id int) returns varchar(2000)
AS
begin
      Declare @var varchar(2000)
      Set @var=”;

      Select  @var=@var+'[‘+UserName+’], ‘

      from Users

      Where Userid=@id

      return @var

end

 

Step 1:: Call Function in Query

Select tid,dbo.RowToSep(tid) from usert

Advertisements