Извините, что беспокою всех тем, что должно быть тривиальным вопросом, но мне нужно импортировать запрос SQL в построитель отчетов SSRS, а затем превратить его в выражение (чтобы я мог использовать его оператор конкатенации для объединения значений параметр в строки поиска).
На первом этапе я скопировал и вставил свой запрос (который, как я знаю, работает) в SSRS, и он прошел гладко. Однако, как только я поместил выражение в кавычки и поставил перед ним префикс «=», я получил несколько очень бесполезных сообщений об ошибках синтаксиса.
Это мой (правильно работающий) запрос перед импортом в SSRS:
DECLARE @From Date='1/1/2015'
DECLARE @To Date='1/3/2020'
DECLARE @Doctors varchar(5)='ABC'
DECLARE @Intents varchar(20)='RoutineRad-Cat2'
DECLARE @DiagnosisTypes varchar(20)='ICD-10'
SET transaction isolation level read uncommitted;
SELECT
x.Expression1 as 'Intent',
x.IntentCategory,
x.StartDateTime as 'Ready To Start Treatment Date',
x.LastName as 'Surname',
x.PatientId as 'Patient ID',
x.DoctorId as 'Primary Oncologist',
x.TreatmentStartTime as 'First RT Treatment Date',
datediff(dd, x.StartDateTime, x.TreatmentStartTime) as 'Wait in days',
x.TargetMet,
x.Delayed,
x.TxStartSortDate
FROM (VALUES('C50%'),('D05%'),('C61%'))
AS v (pattern)
CROSS APPLY
(
SELECT
lut.Expression1,
p.PatientId,
p.LastName,
c.StartDateTime,
d.DoctorId,
rh.TreatmentStartTime,
CASE
WHEN Expression1 like '%Rad%' THEN 'Radical'
WHEN Expression1 like '%Pall%' THEN 'Palliative'
WHEN Expression1 = 'Emergency' THEN 'Emergency'
ELSE 'Other'
END
as 'IntentCategory',
CASE WHEN Expression1 like '%Delay%' THEN 1 ELSE 0 END as 'Delayed',
CASE WHEN
(
(Expression1 like '%Rad%' AND datediff(dd, c.StartDateTime, FirstRadiationHstry.TreatmentStartTime) <= 28)
OR (Expression1 like '%Palliative%' AND datediff(dd, c.StartDateTime, FirstRadiationHstry.TreatmentStartTime) <= 14)
OR (Expression1 = 'Emergency' AND datediff(dd, c.StartDateTime, FirstRadiationHstry.TreatmentStartTime) <= 1)
--catch any exceptions
OR ((Expression1 not like '%Rad%') AND (Expression1 not like '%Palliative%') AND (Expression1!='Emergency'))
) THEN 1 ELSE 0 END as 'TargetMet',
FORMAT(rh.TreatmentStartTime,'yyyyMM') as 'TxStartSortDate',
FirstRadiationHstry.TreatmentStartTime as 'MinTreatStart',
datediff(dd, c.StartDateTime, rh.TreatmentStartTime) as 'TreatDelay'
FROM
dbo.Patient p
inner join Course c on (c.PatientSer = p.PatientSer)
inner join CourseDiagnosis cd on (cd.CourseSer=c.CourseSer)
inner join Diagnosis diag on (diag.DiagnosisSer=cd.DiagnosisSer)
inner join PatientDoctor pd on (pd.PatientSer = p.PatientSer)
inner join Doctor d on (d.ResourceSer = pd.ResourceSer)
inner join dbo.PhysicianIntent phi on (phi.CourseSer = c.CourseSer)
inner join dbo.LookupTable lut on (lut.LookupValue = phi.TreatmentIntentType and lut.ListSelector = 'COURSE_INTENT')
inner join dbo.PlanSetup ps on (ps.CourseSer = c.CourseSer)
inner join dbo.Radiation r on (r.PlanSetupSer = ps.PlanSetupSer)
inner join dbo.RadiationHstry rh on (rh.RadiationSer = r.RadiationSer)
inner join (
select distinct
min(rh_sub.TreatmentStartTime) over (partition by ps_sub.CourseSer) as 'TreatmentStartTime',
ps_sub.CourseSer
from
RadiationHstry rh_sub
inner join dbo.Radiation r_sub on (r_sub.RadiationSer = rh_sub.RadiationSer)
inner join dbo.PlanSetup ps_sub on (r_sub.PlanSetupSer = ps_sub.PlanSetupSer)
where
rh_sub.TreatmentDeliveryType like 'TREATMENT'
) as FirstRadiationHstry on (FirstRadiationHstry.CourseSer = c.CourseSer)
WHERE
datediff(dd, @From, rh.TreatmentStartTime) >= 0
and datediff(dd, rh.TreatmentStartTime, @To)>=0
and diag.DiagnosisCode like v.pattern
and d.OncologistFlag=1
and d.DoctorId in (@Doctors)
and rh.TreatmentStartTime = FirstRadiationHstry.TreatmentStartTime
and lut.Expression1 in (@Intents)
and diag.DiagnosisTableName in(@DiagnosisTypes)
and lut.Expression1 not like 'Dummy Course'
) AS x
;
... и это после:
="SET transaction isolation level read uncommitted;
SELECT
x.Expression1 as 'Intent',
x.IntentCategory,
x.StartDateTime as 'Ready To Start Treatment Date',
x.LastName as 'Surname',
x.PatientId as 'Patient ID',
x.DoctorId as 'Primary Oncologist',
x.TreatmentStartTime as 'First RT Treatment Date',
datediff(dd, x.StartDateTime, x.TreatmentStartTime) as 'Wait in days',
x.TargetMet,
x.Delayed,
x.TxStartSortDate
FROM (VALUES('C50%'),('D05%'),('C61%'))
AS v (pattern)
CROSS APPLY
(
SELECT
lut.Expression1,
p.PatientId,
p.LastName,
c.StartDateTime,
d.DoctorId,
rh.TreatmentStartTime,
CASE
WHEN Expression1 like '%Rad%' THEN 'Radical'
WHEN Expression1 like '%Pall%' THEN 'Palliative'
WHEN Expression1 = 'Emergency' THEN 'Emergency'
ELSE 'Other'
END
as 'IntentCategory',
CASE WHEN Expression1 like '%Delay%' THEN 1 ELSE 0 END as 'Delayed',
CASE WHEN
(
(Expression1 like '%Rad%' AND datediff(dd, c.StartDateTime, FirstRadiationHstry.TreatmentStartTime) <= 28)
OR (Expression1 like '%Palliative%' AND datediff(dd, c.StartDateTime, FirstRadiationHstry.TreatmentStartTime) <= 14)
OR (Expression1 = 'Emergency' AND datediff(dd, c.StartDateTime, FirstRadiationHstry.TreatmentStartTime) <= 1)
--catch any exceptions
OR ((Expression1 not like '%Rad%') AND (Expression1 not like '%Palliative%') AND (Expression1!='Emergency'))
) THEN 1 ELSE 0 END as 'TargetMet',
FORMAT(rh.TreatmentStartTime,'yyyyMM') as 'TxStartSortDate',
FirstRadiationHstry.TreatmentStartTime as 'MinTreatStart',
datediff(dd, c.StartDateTime, rh.TreatmentStartTime) as 'TreatDelay'
FROM
dbo.Patient p
inner join Course c on (c.PatientSer = p.PatientSer)
inner join CourseDiagnosis cd on (cd.CourseSer=c.CourseSer)
inner join Diagnosis diag on (diag.DiagnosisSer=cd.DiagnosisSer)
inner join PatientDoctor pd on (pd.PatientSer = p.PatientSer)
inner join Doctor d on (d.ResourceSer = pd.ResourceSer)
inner join dbo.PhysicianIntent phi on (phi.CourseSer = c.CourseSer)
inner join dbo.LookupTable lut on (lut.LookupValue = phi.TreatmentIntentType and lut.ListSelector = 'COURSE_INTENT')
inner join dbo.PlanSetup ps on (ps.CourseSer = c.CourseSer)
inner join dbo.Radiation r on (r.PlanSetupSer = ps.PlanSetupSer)
inner join dbo.RadiationHstry rh on (rh.RadiationSer = r.RadiationSer)
inner join (
select distinct
min(rh_sub.TreatmentStartTime) over (partition by ps_sub.CourseSer) as 'TreatmentStartTime',
ps_sub.CourseSer
from
RadiationHstry rh_sub
inner join dbo.Radiation r_sub on (r_sub.RadiationSer = rh_sub.RadiationSer)
inner join dbo.PlanSetup ps_sub on (r_sub.PlanSetupSer = ps_sub.PlanSetupSer)
where
rh_sub.TreatmentDeliveryType like 'TREATMENT'
) as FirstRadiationHstry on (FirstRadiationHstry.CourseSer = c.CourseSer)
WHERE
datediff(dd, @From, rh.TreatmentStartTime) >= 0
and datediff(dd, rh.TreatmentStartTime, @To)>=0
and diag.DiagnosisCode like v.pattern
and d.OncologistFlag=1
and d.DoctorId in (@Doctors)
and rh.TreatmentStartTime = FirstRadiationHstry.TreatmentStartTime
and lut.Expression1 in (@Intents)
and diag.DiagnosisTableName in(@DiagnosisTypes)
and lut.Expression1 not like 'Dummy Course'
) AS x
;"
... но я просто получаю сообщение об ошибке "Неверный синтаксис рядом с ключевым словом" VALUES ". Неверный синтаксис рядом ')'. "
Я не знаю, как go попытаться сгладить это, поскольку я знаю, что мой SQL в порядке. Я попытался импортировать запрос в Scite и посмотрел на окончания строк / специальные символы, но это тоже выглядит нормально.
Может кто-нибудь помочь мне?
С наилучшими пожеланиями
C J