Tuesday, June 26, 2012

Get the Table Column data in a single row with comma separator in SQL


explaining how to get one column data in a single row with comma separator.
by sql function in sql- 2005/sql- 2008


Create Table  tbl_Mail_ids Contains email_ids




CREATE TABLE [dbo].[ tbl_Mail_ids](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Email_ID] [nvarchar](150) NULL,





Create Function Get_Emails That return email ids in single row seperated by comma

ALTER  FUNCTION [dbo].[Get_Emails]
(
@id int 
)
RETURNS nvarchar(4000)
AS
BEGIN

declare @email_list Nvarchar(Max);


With MyCte AS(


SELECT    ' '+ Email_ID
FROM         tbl_Mail_id
)
select @ email_list =
stuff(( 
select  email_list  +'# '  from mycte
for xml path('') ),1,1,'') ;

  Set @email_list  =  REPLACE(@email_list , '#', ',') 

RETURN   @email_list 


END
Execute function  >> select dbo.Get_Emails() 

Save a PDF generated from html2pdf in C#, MVC , html2pdf , Ajax code

 To save on server or disk a PDF generated from HTML in C# code example, you can use the      html2pdf js script     html2pdf   converts any...