我在 SSRS 中运行以下查询。如果我为这两个参数添加声明,它在 SQL 管理控制台中运行良好。
declare @EMRQuery varchar(max)
declare @CPSQuery varchar(max)
set @EMRQuery = 'select Person.ExternalId
from ml.Person
join ml.Obs on Person.pId = Obs.pId
join ml.ObsHead on Obs.hdId = ObsHead.hdId
where ObsHead.name = ''SCHOOLREGDTE''
and Obs.xId = 1.e+035
and Obs.change = 2
and Obs.obsDate >= to_date('''
+ convert(varchar(30), @DateYearStart, 120)
+ ''', ''YYYY-MM-DD HH24:MI:SS'')
and Obs.obsDate < to_date('''
+ convert(varchar(30), @DateQuarterEnd, 120)
+ ''', ''YYYY-MM-DD HH24:MI:SS'')'
set @CPSQuery = 'select ic.ListName, count(distinct pp.patientprofileid) as PatCount
from PatientProfile pp
left join PatientInsurance pi on pp.PatientProfileId = pi.PatientProfileId
and pi.OrderForClaims = 1
and pi.Inactive <> 1
left join InsuranceCarriers ic on pi.InsuranceCarriersId = ic.InsuranceCarriersId
join OpenQuery(EMR_LIVE
, ''' + replace(@EMRQuery, '''', '''''') +
''' ) Students on pp.PatientId = Students.ExternalId
group by ic.ListName '
exec(@CPSQuery)
但是,当我将其插入 SSRS 时,它不会记录有任何可用于报告的字段。我如何说服 SSRS 我确实有可以使用的字段?谢谢。
编辑:我刚刚在查询中声明了参数,它识别了字段名称。
declare @DateYearStart datetime
declare @DateQuarterEnd datetime
set @DateYearStart = '2011-07-01'
set @DateQuarterEnd = '2012-03-31'
当然,这是错误的,因为我声明了两次参数,一次是查询参数,一次是在查询中。但是,一旦我注释掉上面的行,我就再次丢失了这些字段。