Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

A simple query

$
0
0

Hi,

this query works fine

    select tblProductDetails.ProductId as Id,
    stuff((select ',' + CAST(PD2.SpeValue as varchar(100))
    from tblProductDetails PD2 where tblProductDetails.ProductId = PD2.ProductId for xml path('')),1,1,'') Name

    from tblProductDetails group by tblProductDetails.ProductId


Why this query not works

select PD.ProductId as Id,
    stuff((select ',' + CAST(PD2.SpeValue as varchar(100))
    from PD PD2 where PD.ProductId = PD2.ProductId for xml path('')),1,1,'') Name

    from (select ProductId,SpeValue from tblProductDetails) PD group by PD.ProductId


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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