我正在尝试创建一个允许我在SSRS中使用多个VarChars作为参数的查询。
以下是代码:
Declare @CallCodes as VarChar(10)
Set @CallCodes = ('MORC30' , 'Morc60')
;
With Data
AS
(SELECT
VC.[CallCode]
,VC.[HospCode]
,VC.[HospMastID]
,VC.[ClientID]
,Row_Number () Over (Partition By HospMastID, VC.ClientID Order By HospMastID, VC.ClientID, GLCode) as Txn
FROM
[RptSys].[dbo].[CSC_VuesionImport_DevDetl] as VC
Inner Join
[AVimark_OLTP].[dbo].[Client] as C
on
VC.HospMastID = C.HospitalMasterID
and
VC.ClientID = C.ClientID
Inner Join
[Avimark_OLTP].[dbo].[Patient] as P
on
VC.HospMastID = P.HospitalMasterID
and
VC.PatientID = P.PatientID
Inner Join
[Avimark_OLTP].[dbo].[Treatment] as T
on
VC.HospMastID = T.HospitalMasterID
and
VC.MastReminder = T.Code
Where
VC.CallCode in @CallCodes)
当我尝试运行它时会出错。最终输出是允许最终用户从SSRS报告中的下拉列表中进行选择,我已经尝试了where语句的in或like的所有变体。
任何建议都将不胜感激。
答案 0 :(得分:1)
为什么不把Parmaeter放在标有#
的临时表中CREATE TABLE #tmp(
Callcodes varchar(10))
INSERT INTO #tmp
VALUES
('MORC30'),
('Morc60')
With Data
AS
(SELECT
VC.[CallCode]
,VC.[HospCode]
,VC.[HospMastID]
,VC.[ClientID]
,Row_Number () Over (Partition By HospMastID, VC.ClientID Order By HospMastID, VC.ClientID, GLCode) as Txn
FROM
[RptSys].[dbo].[CSC_VuesionImport_DevDetl] as VC
Inner Join
[AVimark_OLTP].[dbo].[Client] as C
on
VC.HospMastID = C.HospitalMasterID
and
VC.ClientID = C.ClientID
Inner Join
[Avimark_OLTP].[dbo].[Patient] as P
on
VC.HospMastID = P.HospitalMasterID
and
VC.PatientID = P.PatientID
Inner Join
[Avimark_OLTP].[dbo].[Treatment] as T
on
VC.HospMastID = T.HospitalMasterID
and
VC.MastReminder = T.Code
Where
VC.CallCode in (SELECT * FROM #tmp))
我希望这就是你要找的,如果不是,请告诉我。或者像评论中提到的那样给出错误信息
度过愉快的一天。来自瑞士的问候
艾蒂安