0
set @sql ='select *
from
(
select tsim.OrganisationCode orgcode , (case when tsim.OrganisationName is not null then ''yes'' else null end) as orgname,p.RouteofAdministration from tbl_Product p
inner join tbl_ProductMaster as pm on p.fk_ProductMasterId=pm.ProductMasterId
inner join tbl_ProductSiteInpectedBy as ps on ps.fk_ProductMasterID=pm.ProductMasterId
inner join tbl_SiteInspectedBy_Master as tsim on tsim.OrganisationID=ps.fk_OrganisationID
) d pivot
(
max(orgcode) for orgname in ('+@columns+')
) as t2'
exec(@sql)
0
not done ....same problem again
0
try this
set @sql ='select *
from
(
select tsim.OrganisationCode orgcode , (case when tsim.OrganisationName is not null then yes else null end) as orgname,p.RouteofAdministration from tbl_Product p
inner join tbl_ProductMaster as pm on p.fk_ProductMasterId=pm.ProductMasterId
inner join tbl_ProductSiteInpectedBy as ps on ps.fk_ProductMasterID=pm.ProductMasterId
inner join tbl_SiteInspectedBy_Master as tsim on tsim.OrganisationID=ps.fk_OrganisationID
) d
pivot
(
max(orgcode) for orgname in ('+@columns+')
) as t2'
exec(@sql)