出现ssrs数据集中没有字段 - 动态SQL

时间:2015-11-11 14:00:34

标签: sql reporting-services

我尝试使用数据库名称作为@CATALOG参数通过SSRS运行,但字段列表不会填充。任何建议将不胜感激。

DECLARE @SQLScript AS NVARCHAR(4000)

SET @SQLScript = 
'USE ' +@CATALOG + CHAR(13) +
'SELECT
    LD.ProvSpecMon_A AS Dept,
    LD.ProvSpecMon_C AS SubjArea,
    LD.ProvSpecMon_B AS CourseCode,
    L.LearnRefNumber AS PersonCode,
    CASE 
        WHEN L.PlanEEPHours + L.PlanLearnHours >= 540 THEN 'FT' 
        ELSE 'PT'
    END AS LearnerType,
    LD.AimType,
    LD.LearnAimRef AS LearningAim,
    AIM.LearnAimRefTitle AS LearningAimTitle,
    EFA.OnProgPayment,
    EFA.StartFund
FROM Valid.Learner L
INNER JOIN Valid.LearningDelivery LD
    ON LD.LearnRefNumber = L.LearnRefNumber
LEFT JOIN Rulebase. DV_Learner AGE
    ON AGE.LearnRefNumber = L.LearnRefNumber
LEFT JOIN Rulebase.EFA_LEARNER EFA
    ON EFA.LearnRefNumber = L.LearnRefNumber
LEFT JOIN Rulebase.EFALearningDeliveryLARSInput AIM
    ON AIM.AimSeqNumber = LD.AimSeqNumber
    AND AIM.LearnRefNumber = LD.LearnRefNumber
WHERE
    EFA.StartFund = 1
    AND LD.AimType = 5
ORDER BY
    L.LearnRefNumber'

EXECUTE sp_executesql @SQLScript

1 个答案:

答案 0 :(得分:1)

如果要对目录进行参数化,则必须对连接字符串进行参数化。

在datasource属性中,选择Embedded connection并将连接字符串表达式与您的参数放在一起。

enter image description here

您可以在连接字符串中使用参数:

="Data Source=" & Parameters!ServerName.Value & ";Initial Catalog=" & Parameters!Catalog.Value