Hi,
I am using a pivot query like below.
IN this I am using @SelPorts variable.If I include this variable I am getting error Incorrect syntax.
Without variable If I directly put values like [EMBIDIV],[AR] I am getting result.
If I assign in variable and try to use it I am getting syntax error in @SelPorts.
can somebody plz help in this.
Select * from (select Por.ShortName, IsNull(IsNull(SM.SecDesc, rtrim(SM.SecName)), SM.PrimarySecID) as SecName,
SM.SecID,IsNull(SM.BBSectorName, 'zOthers') AssetClass, 0.00 as MarketValue,
round(MVUSD,0) MVUSD From vwYBPositions Pos, vwSecMaster SM, Portfolio Por
where Pos.Portfolio_id = Por.Portfolio_ID and
Por.ShortName in ('EMBIDIV','AMEX','AMR')
and Pos.Security_ID = SM.SecID and MVUSD <> 0 and pos.AsOfDt = '12/27/2006' ) as D
PIVOT(SUM(MVUSD) FOR ShortName IN(@SelPorts)) AS P order by 1, 2;
I am using a pivot query like below.
IN this I am using @SelPorts variable.If I include this variable I am getting error Incorrect syntax.
Without variable If I directly put values like [EMBIDIV],[AR] I am getting result.
If I assign in variable and try to use it I am getting syntax error in @SelPorts.
can somebody plz help in this.
Select * from (select Por.ShortName, IsNull(IsNull(SM.SecDesc, rtrim(SM.SecName)), SM.PrimarySecID) as SecName,
SM.SecID,IsNull(SM.BBSectorName, 'zOthers') AssetClass, 0.00 as MarketValue,
round(MVUSD,0) MVUSD From vwYBPositions Pos, vwSecMaster SM, Portfolio Por
where Pos.Portfolio_id = Por.Portfolio_ID and
Por.ShortName in ('EMBIDIV','AMEX','AMR')
and Pos.Security_ID = SM.SecID and MVUSD <> 0 and pos.AsOfDt = '12/27/2006' ) as D
PIVOT(SUM(MVUSD) FOR ShortName IN(@SelPorts)) AS P order by 1, 2;