我正在尝试使用Microsoft Visual Studio 2010上的SQL Server报表创建报表。我面临的问题是,当我尝试在新数据集中添加查询时,我收到一条错误消息:“无法更新字段列表用于查询。验证您可以连接到数据源,并且查询语法正确。” 。创建其他报告时我没有遇到问题,并且查询在SQL Server上工作得很好,但似乎我必须以不同的方式重新编写查询,以便它可以在SQL Server报表上工作。我不确定如何重新编写查询以及确切的问题是什么。
查询是:
-- PreTerm Still birth
WITH
cteCond1Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
LEFT JOIN v_dbPatientsAdditions pe ON pe.PatientID = pa.PatientID
WHERE pd.DiseaseID IN (139061, 128466, 128462, 128463, 128464, 128465, 128466, 128467, 128663, 128662, 128661, 104860, 104859, 104857, 1397)
AND pa.PatientType = 2),
cteCond1 AS
(SELECT COUNT(*) AS PreTerm_Still_Birth,
COUNT(CASE WHEN cteCond1Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond1Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond1Pre
JOIN v_dbDiseases d ON d.DiseaseID = cteCond1Pre.secondDia
WHERE cteCond1Pre.DiseaseID IN (128466, 128462, 128463, 128464, 128465, 128466, 128467, 128663, 128662, 128661, 104860, 104859, 104857, 1397)
AND cteCond1Pre.AdmitDate > '2019-01-01'
AND cteCond1Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10')
AND secondDia IN (139061)
-- FullTerm Still birth
),
cteCond2Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pd.DiseaseID NOT IN (128466, 128462, 128463, 128464, 128465, 128466, 128467, 128663, 128662, 128661, 104860, 104859, 104857, 1397)
AND pa.PatientType = 2),
cteCond2 AS
(SELECT COUNT(*) AS FullTerm_Still_Birth,
COUNT(CASE WHEN cteCond2Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S2,
COUNT(CASE WHEN cteCond2Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS2
FROM cteCond2Pre
JOIN v_dbDiseases d ON d.DiseaseID = cteCond2Pre.secondDia
WHERE cteCond2Pre.DiseaseID NOT IN (128462, 128463, 128464, 128465, 128466, 128467, 128663, 128662, 128661, 104860, 104859, 104857, 1397)
AND secondDia IN (139061)
AND cteCond2Pre.AdmitDate > '2019-01-01'
AND cteCond2Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10')),
--Fullterm_Live_Birth
cteCond3Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(pa.AdmitDate) OVER (PARTITION BY pa.regcode ORDER BY pa.admitdate) AS next_AdmitDate,
pa.PatientID,
p.FirstName
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbPatientsAdditions pe ON pe.ParentPatientid = pa.PatientID
JOIN v_dbpatients p ON p.PatientID = pe.PatientID
WHERE pd.DiseaseID IN (139060)),
cteCond3 AS
(SELECT COUNT(*) AS Fullterm_Live_Birth,
COUNT(CASE WHEN cteCond3Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S3,
COUNT(CASE WHEN cteCond3Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS3
FROM cteCond3Pre
WHERE cteCond3Pre.AdmitDate > '2019-01-01'
AND cteCond3Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10')),
-- fullterm Low Birth weight
cteCond4Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbpatients pp ON pp.PatientID = pa.PatientID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pd.DiseaseID IN (104846, 104847, 104848, 104849, 104850, 104851, 104852, 104853, 8103, 8102, 104843)
AND pa.PatientType = 2),
cteCond4 AS
(SELECT COUNT(*) AS Fullterm_Low_BirthWeight,
COUNT(CASE WHEN cteCond4Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond4Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond4Pre
WHERE cteCond4Pre.AdmitDate > '2019-01-01'
AND cteCond4Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10')),
-- Delivery_Other-Twinss
cteCond5Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbpatients pp ON pp.PatientID = pa.PatientID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pa.PatientType = 2),
cteCond5 AS
(SELECT COUNT(*) AS Delivery_Other_Twinss,
COUNT(CASE WHEN cteCond5Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond5Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond5Pre
WHERE cteCond5Pre.DiseaseID IN (11866)
OR (cteCond5Pre.DiseaseID IN (128576)
AND cteCond5Pre.secondDia IN (139060)
AND cteCond5Pre.AdmitDate > '2019-01-01'
AND cteCond5Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10'))),
-- Delivery_CS
cteCond6Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbpatients pp ON pp.PatientID = pa.PatientID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pd.DiseaseID IN (140540)
AND pa.PatientType = 2),
cteCond6 AS
(SELECT COUNT(*) AS Delivery_CS,
COUNT(CASE WHEN cteCond6Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond6Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond6Pre
WHERE cteCond6Pre.AdmitDate > '2019-01-01'
AND cteCond6Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10')),
-- Delivery_Forceps
cteCond7Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbpatients pp ON pp.PatientID = pa.PatientID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pd.DiseaseID IN (140539)
AND pa.PatientType = 2),
cteCond7 AS
(SELECT COUNT(*) AS Delivery_Forceps,
COUNT(CASE WHEN cteCond7Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond7Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond7Pre
WHERE cteCond7Pre.AdmitDate > '2019-01-01'
AND cteCond7Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10')),
-- Delivery_Breech
cteCond8Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbpatients pp ON pp.PatientID = pa.PatientID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pd.DiseaseID IN (128680, 104824)
AND pa.PatientType = 2),
cteCond8 AS
(SELECT COUNT(*) AS Delivery_Breech,
COUNT(CASE WHEN cteCond8Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond8Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond8Pre
WHERE cteCond8Pre.AdmitDate > '2019-01-01'
AND cteCond8Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10')),
-- Delivery_Ventouse(Vacuum Extractor)
cteCond9Pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbpatients pp ON pp.PatientID = pa.PatientID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pd.DiseaseID IN (140539)
AND pa.PatientType = 2),
cteCond9 AS
(SELECT COUNT(*) AS Delivery_Ventouse,
COUNT(CASE WHEN cteCond9Pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond9Pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond9Pre
WHERE (cteCond9Pre.AdmitDate > '2019-01-01'
AND cteCond9Pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10'))),
-- Delivery_Normal-Single-Spontanous
cteCond10pre AS
(SELECT DISTINCT
pa.AdmitDate,
pa.AdmissionID,
pa.RegCode,
d.DiseaseName,
d.DiseaseID,
pe.NationalityID,
LEAD(d.DiseaseID) OVER (PARTITION BY pa.AdmissionID ORDER BY pd.DiseaseID) AS secondDia
FROM v_dbPatientAdmissions pa
JOIN v_dbPatientMonitoring pm ON pm.IPID = pa.AdmissionID
JOIN v_DBPatientDiseases pd ON pd.MonitorID = pm.MonitorID
JOIN v_dbDiseases d ON pd.DiseaseID = d.DiseaseID
JOIN v_dbpatients pp ON pp.PatientID = pa.PatientID
LEFT JOIN v_dbPatientsAdditions pe ON pe.Patientid = pa.PatientID
WHERE pd.DiseaseID IN (140538)
AND pa.PatientType = 2),
cteCond10 AS
(SELECT COUNT(*) AS Delivery_Normal_Single_Spontanous,
COUNT(CASE WHEN cteCond10pre.NationalityID = 1 THEN 1 ELSE NULL END) AS S,
COUNT(CASE WHEN cteCond10pre.NationalityID != 1 THEN 2 ELSE NULL END) AS NS
FROM cteCond10pre
WHERE cteCond10pre.AdmitDate > '2019-01-01'
AND cteCond10pre.AdmitDate < DATEADD(DAY, 1, '2019-10-10'))
SELECT *
FROM cteCond1
CROSS JOIN cteCond2
CROSS JOIN cteCond3
CROSS JOIN cteCond4
CROSS JOIN cteCond5
CROSS JOIN cteCond6
CROSS JOIN cteCond7
CROSS JOIN cteCond8
CROSS JOIN cteCond9
CROSS JOIN cteCond10;
答案 0 :(得分:0)
尝试在WITH前面加上分号(;)
答案 1 :(得分:0)
我在SSRS上为每个子查询创建了多个数据集,并且效果很好!