DECLARE @tablename as varchar(MAX);
SET @tablename = '[dbo].[A_E_att_rate]
,[Acute_total_cost]
,[Average_los]
,[D_days]
,[days_1000]
,[rate]';
WHILE (SELECT * from [dbo].[fnSplitListToTable](@tablename)) > 0
BEGIN
EXEC(' SELECT t.[Commissionercode],
t.[RiskBand Qadm],
x.Col,
x.Value
FROM' + @tablename +' t
CROSS APPLY
(
VALUES
(''August'', t.[Sum of Aug12-Jul13]),
(''July'', t.[Sum of Jul12-Jun13]),
(''June'', t.[Sum of Jun12-May13]),
(''May'', t.[Sum of May12-Apr13]),
(''April'', t.[Sum of Apr12-Mar13])
) x (Col, Value)')
END
在上面的查询中,我试图从变量@tablename 中获取表名。这是一个逗号分隔的值。我有兴趣在循环中使用每个表名。我该怎么做呢 ?