Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

Collapse Rows into JSON Value

$
0
0

I have the following code to Collapse rows into JSON and XML PATH WITH STUFF Operation is very slow.

Looked into alternatives and couldn't find anything suits my needs.

Is there better way to collapse rows and create JSON String ?

Thanks,

I90Runner


SELECT @AffiliateID AS AffiliateID, AttributeName, AttributeValue FROM ( SELECT DISTINCT Attribute AS AttributeName, ( SELECT '['+ STUFF ( ( ( SELECT ',' + Value AS [text()] FROM @TMP_ATTRIBUTES WHERE Category = t.Category AND Category IN ( SELECT Category FROM dbo.Attribute WITH (NOLOCK) WHERE AttributeType= 'CP.AffiliateAttributeList' ) ORDER BY Value FOR XML PATH(N''), TYPE ).value('.[1]', 'varchar(max)') ), 1, 1, '' )+ ']' ) AS AttributeValue FROM @TMP_ATTRIBUTES t WHERE Category IN ( SELECT Category FROM dbo.Attribute WITH (NOLOCK) WHERE AttributeType= 'CP.AffiliateAttributeList' )



I90Runner


Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>