Wednesday, 26 April 2017

open Xml in sql or comma sepreted value in sql

==================
for open Xml
==================

(select  STUFF((SELECT ', ' + cast( CustomerID as nvarchar(20)) FROM UsedDealDetail WHERE cast(CouponUsedDate as date) =cast(ud.CouponUsedDate as date) FOR XML PATH('') ), 1, 2, '')) as userid


=================
for variable
=================
  declare @tmp varchar(2500),@customerid varchar(2500)
      SET @tmp = ''
      select @tmp = @tmp + Cast(CustomerID as nvarchar(10)) + ', ' from  UsedDealDetail where VendorID=@vendoeId group by CustomerID

set @customerid=SUBSTRING(@tmp, 0, LEN(@tmp))

No comments:

Post a Comment