0
我正在学习编写动态查询,所以道歉如果下面是混乱。动态选择查询与枢轴
我的问题是为什么下面的行不起作用。 @fxPair
变量以红色下划线。在我看来,它是一个字符串变量,所以我看不到问题?有没有更好的方法来做到这一点?
source pivot(max(Mvalue) for Currency in (@fxPair) as pvt
我的查询:
declare @FundsT table (fund nvarchar(10))
insert into @FundsT
select SubPot
from tblF
where Fund = @FundCode
order by SubPot
declare @fxPair nvarchar(max) = ''
select @fxPair = @fxPair + '[' + Currency + '], '
from tblCurrency
where DateH = @DateHld
and FundCode in (select fund from @FundsT)
group by Currency
set @fxPair = SUBSTRING(@fxPair, 1, len(@fxPair) - 1)
--print @fxPair
select *
from
(select
FundCode, IssueGrpType, Currency, Sum(MktValDirty) Mvalue
from
Holdings_SS
where
DateHolding = @DateHld
and FundCode in (select fund from @FundsT)
group by
FundCode, IssueGrpType, Currency) source
pivot
(max(Mvalue) for Currency in (@fxPair) as pvt
order by
FundCode, IssueGrpType
你今天早些时候提出了一个关于这个查询的问题,这里的问题也非常多。你的代码评估为'... in('[x],[y]')',你想要的是... ...('[x]','[y]')'。 – HoneyBadger