sql server - Select Top 2 Comma Delimited w/SQL -
i trying select top 2 records , set them in 1 column separated comma.
here have far, can't work.
update #temp set toptwoinactiveddsrenewalfeeid = ( stuff ( select top 2 ',' + i.invoiceid db..rinvoice i.rultimateentityid = entid , i.objectid = 18 , i.objecttypeidraw = 1741 , i.rparentobjectid = 2 , i.rparentpk = licid xml path ('')),1,2,'') ) msg 156, level 15, state 1, line 3 wrong syntax near keyword 'select'. msg 102, level 15, state 1, line 10 wrong syntax near ')'.
i using post reference, it's not working me: display top 3 records in comma separated in 1 column
not sure how write one.
i seek alter next line. having space after comma necessary stuff work properly. improve if load test info sqlfiddle http://sqlfiddle.com/.
select top 2 ',' + i.invoiceid to
select top 2 ', ' + i.invoiceid here's illustration you,
if object_id('tempdb..#values') not null begin drop table #values end if object_id('tempdb..#temp') not null begin drop table #temp end create table #temp ( id int ,commadelimited varchar(500) ) insert #temp ( id ) select 1 create table #values ( value char(1) ) insert #values ( value ) select '1' union select '2' union select '3' union select '4' update #temp set commadelimited = stuff((select top 2 ', '+value #values xml path('')),1,2,'') select * #temp sql sql-server tsql
No comments:
Post a Comment