Venkat Govind

Venkat Govind

  • 1.2k
  • 557
  • 67k

Hcan i pass where condition in below query?

May 23 2015 4:49 AM
DECLARE @WFavailablequery nVARCHAR(max)
DECLARE @WFavailablecolumn nVARCHAR(max)
SELECT @WFavailablecolumn = STUFF(( SELECT'],['+ Tradecat FROM mstr_tradecategory order by '],[' + convert(nVARCHAR(max),Tradecat) FOR XML PATH('')), 1, 2, '') + ']'
SET @WFavailablequery ='SELECT VendorName,VendorCode,' + @WFavailablecolumn + ' FROM( SELECT wf.VendorCode,VendorName,Tradecat
FROM dbo.mstr_workforce as wf inner join mstr_vendor as v on v.VendorCode=wf.VendorCode
left outer join mstr_tradecategory as tc on tc.TrcatCode=wf.Category where v.VendorCode='+LTSBV000001+')
mstr_workforce PIVOT (count(Tradecat) FOR Tradecat IN ('+@WFavailablecolumn+')) AS pvt'
EXECUTE (@WFavailablequery)
Hi Please help me any one ,
I dont know how pass where condition in above query  

Answers (1)