Friday, January 27, 2012

csv values in single query



create table emailData
(
id int identity(1,1),
email varchar(30)
)
insert into emaildata values('nbravrani@india.com')
insert into emaildata values('mohit.raiyani@india.com')
insert into emaildata values('jkundal@india.com')
insert into emaildata values('vimal@india.com')
insert into emaildata values('ravijohsi@india.com')
insert into emaildata values('sutariya.bhadresh@india.com')
insert into emaildata values('riteshpatadiya@india.com')
insert into emaildata values('ajay@india.com')


Que:
O/P like(Comma seperated using single query):
nbravrani@india.com,mohit.raiyani@india.com,.....


ANS:
select email + ',' from emailData for xml path('')

No comments:

Post a Comment