我已经编写并重写了一份医院人口普查查询,我想为其创建每日Windows文件共享订阅。查询似乎很好;它在SSMS,BIDS和SSRS报告服务器本身中正常运行。但是,当我创建任何类型的订阅时,有时报表上会有旧的和不正确的数据。据我所知,当报告生成错误时,没有真正的模式,但是错误发送的数据始终是相同的,并且是从1月份开始的。我最初在具有相同数据的测试服务器上编写了查询,只是稍微过了一点,并且更改了它将运行的日期。在进行更改后,我还必须重新部署报告几次。我最初是从测试系统直接部署到实时服务器,所以我尝试在实时系统中完全重做它,除了做一些改进以提高性能,但我仍然得到相同的错误数据。
任何想法都会在这一点上受到高度赞赏,因为我很茫然,我真的只是开始使用SQL
谢谢你的帮助。
编辑:添加返回不一致数据的查询;删除我的代码格式不佳的评论 此外,更具体地说明问题:订阅有时会按预期发送前一天的人口普查数据,有时它会从1月15日开始发送人口普查数据,而这只发生在订阅中。
查询1:
SELECT
V.Name AS PatientName
,V.AccountNumber AS AccountNumber
,V.FinancialClassName AS FinancialClass
,V.ServiceDateTime
,P.EmergencyID AS Provider
,X.ErDateTime AS Discharge
,X.ErDispositionID AS Disposition
FROM dbo.AdmVisits AS V
INNER JOIN dbo.AdmProviders AS P
ON P.VisitID=V.VisitID
INNER JOIN dbo.AdmDischarge AS X
ON V.VisitID=X.VisitID
WHERE CAST(V.ServiceDateTime AS DATE)=CAST(DATEADD(day,-1,GETDATE()) AS DATE)
OR CAST(X.ErDateTime AS DATE)=CAST(DATEADD(day,-1,GETDATE()) AS DATE)
ORDER BY V.Name
查询2:
SELECT
V.Name
,V.AccountNumber
,V.FinancialClassName
,V.InpatientServiceID
,V.RoomID
,D.AdmitDateTime
,P.AdmitID
,P.AttendID
,X.DischargeDateTime
,X.DispositionName
FROM dbo.AdmVisits AS V
INNER JOIN dbo.AdmittingData AS D
ON V.VisitID=D.VisitID
INNER JOIN dbo.AdmProviders AS P
ON P.VisitID=D.VisitID
LEFT OUTER JOIN dbo.AdmDischarge AS X
ON V.VisitID=X.VisitID
WHERE V.InpatientOrOutpatient='I'
AND NOT V.InpatientServiceID='INP LTC'
AND (CAST(D.AdmitDateTime AS DATE)<CAST(GETDATE()AS DATE))
AND (V.Status='ADM IN' OR CAST(X.DischargeDateTime AS DATE)=CAST(DATEADD(DAY,-1,GETDATE()) AS DATE))
ORDER BY V.Name
查询3:
SELECT
V.Name
,V.AccountNumber
,V.FinancialClassName
,V.InpatientServiceID
,V.RoomID
,D.AdmitDateTime
,P.AdmitID
,P.AttendID
,X.DischargeDateTime
,X.DispositionName
,CASE
WHEN V.LoaStatus IN('F','L') THEN CAST(V.LoaEffectiveDateTime AS varchar)
Else 'No'
END AS 'LeaveOfAbsence'
FROM dbo.AdmVisits AS V
INNER JOIN dbo.AdmittingData AS D
ON V.VisitID=D.VisitID
INNER JOIN dbo.AdmProviders AS P
ON P.VisitID=D.VisitID
LEFT OUTER JOIN dbo.AdmDischarge AS X
ON V.VisitID=X.VisitID
WHERE V.InpatientServiceID='INP LTC'
AND (CAST(D.AdmitDateTime AS DATE)<CAST(GETDATE()AS DATE))
AND (V.Status='ADM IN' OR CAST(X.DischargeDateTime AS DATE)=CAST(DATEADD(DAY,-1,GETDATE()) AS DATE))
ORDER BY V.Name
答案 0 :(得分:0)
事实证明,问题是数据源与服务器的连接字符串。我使用'localhost'而不是服务器的实际名称,并且由于测试和实时服务器基本上是彼此的克隆,我认为它不是始终连接到正确的服务器。不知道究竟是如何运作的,但报告现在正在运作。