Ich habe eine Abfrage geschrieben und es läuft gut als Select-Anweisung in SSMS, aber wenn ich versuche, es als eine Sicht zu speichern, erhalte ich einen Fehler Fenster mit „falscher Syntax nahe‚Arbeitnehmer‘, falsche Syntax nahe dem Schlüsselwort‚AS‘(diese Linie, bis sie die ersten 6 Zeichen der Zeile zeigt am unteren Rande des Dialogfelds gerade wiederholt wird.Falsche Syntax in der Nähe von "Worker", falsche Syntax in der Nähe des Schlüsselwortes "AS"
SELECT
dbo.emh_case_data.case_data_id AS 'IR Form ID',
emh_program.program_name AS 'Program History Name',
dbo.emh_case_data.date AS 'IR Date-Time',
datepart (weekday, emh_case_data.date) AS 'Day of Week',
convert(char(8),emh_case_data.date,108) as 'Time of Day',
emh_client.id as 'ClientID',
dob.date_value as 'DOB',
emh_worker.last_name + ', ' + emh_worker.first_name As 'PrimtaryReportWorker',
programresidence.string_value As 'Program',
incidentreason.string_value as 'IR Type',
irlocation.string_value as 'Incident Loc',
verbalo.string_value as '(4) Verbal Other',
sharps.string_value As '(16) Contraband Comments',
dateleft.date_value as '(17) LWP - Time left',
clientreturned.boolean_value as '(17) Client Returned',
datereturned.date_value as '(17) LWP - Time Returned',
irother.string_value As '(21) IR Type Other',
supervisorysupport.boolean_value AS '(1) Supervisory Support',
individualprogram.boolean_value AS '(2) Individualized Program',
individualprograml.string_value AS '(2) Location',
crisisclinic.boolean_value AS '(3) Crisis Clinic',
urgentcare.boolean_value as '(4) Urgent Care',
urgentcarereason.string_value As '(4) Reason',
urgentcareo.string_value as '(4) Reason Other',
callpolice.boolean_value as '(5) Call Police Dispatch',
callpolicetc.number_value as '(5) Time Called',
callpolicetr.number_value as '(5) Time Response',
call911.boolean_value as '(6) Call 911',
call911t.number_value as '(6) Time Called',
hospital.boolean_value as '(7) Taken to Hospital',
hospitallocation.string_value AS '(7) Location',
hospitaladmitted.boolean_value As '(7) Admitted?',
hospitalreason.string_value as '(7) Reason',
hospitalreasono.string_value As '(7) Reason Other',
staffhurt.boolean_value as '(8) Staff Hurt',
staffhurtr.string_value as '(8) Result of',
staffsor.boolean_value as '(8) Occurance Report',
debriefr.boolean_value as '(9) Debrief Room',
debriefrts.number_value as '(9) Time Started',
debriefrte.number_value as '(9) Time Ended',
debriefrtt.number_value as '(9) Total Time',
physguid.boolean_value AS '(10) Physical Guidence',
pmab.boolean_value as '(11) PMAB Blocks',
pmabt.string_value as '(11) Type Used',
releasepoints.boolean_value as '(12) Release Points',
releasepointst.string_value as '(12) Type',
clientdebrief.boolean_value as 'Client Debriefed',
clientdebriefdt.date_value as 'Client Debief Date/Time',
clientdebriefworker.Worker as 'Client Debriefed by',
staffdebrief.boolean_value as 'Staff was Debriefed',
staffdebriefdt.date_value as 'Staff Debrief Date/Time',
staffdebriefworker.Worker as 'Staff Debriefed by',
riskdebrief.string_value As 'Risk Debrief',
followup.boolean_value as 'Follow Up Report Required',
sorr.boolean_value as 'SOR Required',
sorrw.worker as 'SOR Initiated by',
sortype.string_value as 'Non YJ SOR Type',
yjsortype.string_value as 'YJ SOR Type',
FROM
dbo.emh_case_data JOIN
emh_program on emh_case_data.program_id = emh_program.program_id JOIN
emh_client on emh_client.client_id = emh_case_data.client_id JOIN
emh_worker on emh_worker.worker_id = emh_case_data.worker_id LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_1_1_4')
as programresidence on programresidence.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_4_4_1')
as incidentreason on incidentreason.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.date_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_1_1_2' )
as dob on dob.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_4_4_2')
as irlocation on irlocation.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_4_4_3' )
as verbalo on verbalo.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_4_4_4' )
as sharps on sharps.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.date_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_4_4_5' )
as dateleft on dateleft.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.date_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_4_4_7' )
as datereturned on datereturned.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_4_4_6' )
as clientreturned on clientreturned.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_4_4_8' )
as irother on irother.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_1' )
as supervisorysupport on supervisorysupport.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_2' )
as individualprogram on individualprogram.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_6_6_3')
as individualprograml on individualprograml.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_4' )
as crisisclinic on crisisclinic.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_5' )
as urgentcare on urgentcare.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_6_6_6')
as urgentcarereason on urgentcarereason.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_7' )
as urgentcareo on urgentcareo.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_8' )
as callpolice on callpolice.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.number_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_9' )
as callpolicetc on callpolicetc.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.number_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_10' )
as callpolicetr on callpolicetr.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_11' )
as call911 on call911.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.number_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_12' )
as call911t on call911t.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_13' )
as hospital on hospital.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_6_6_14')
as hospitallocation on hospitallocation.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_15' )
as hospitaladmitted on hospitaladmitted.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_6_6_16')
as hospitalreason on hospitalreason.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_17' )
as hospitalreasono on hospitalreasono.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_18' )
as staffhurt on staffhurt.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_6_6_19')
as staffhurtr on staffhurtr.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_20' )
as staffsor on staffsor.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_21' )
as debriefr on debriefr.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.number_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_22' )
as debriefrts on debriefrts.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.number_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_23' )
as debriefrte on debriefrte.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.number_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_24' )
as debriefrtt on debriefrtt.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_25' )
as physguid on physguid.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_26' )
as pmab on pmab.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_6_6_27')
as pmabt on pmabt.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_28' )
as releasepoints on releasepoints.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_6_6_29' )
as releasepointst on releasepointst.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_11_11_1' )
as clientdebrief on clientdebrief.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.date_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_11_11_3' )
as clientdebriefdt on clientdebriefdt.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value, emh_worker.last_name + ', ' + emh_worker.first_name as 'Worker'
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_11_11_4' join
emh_worker on emh_worker.worker_id = dr_entity.string_value )
as clientdebriefworker on clientdebriefworker.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_11_11_5' )
as staffdebrief on staffdebrief.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.date_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_11_11_7' )
as staffdebriefdt on staffdebriefdt.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value, emh_worker.last_name + ', ' + emh_worker.first_name as 'Worker'
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_11_11_8' join
emh_worker on emh_worker.worker_id = dr_entity.string_value )
as staffdebriefworker on staffdebriefworker.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_11_11_9')
as riskdebrief on riskdebrief.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_12_12_1' )
as followup on followup.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.boolean_value
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_12_12_2' )
as sorr on sorr.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_entity.string_value, emh_worker.last_name + ', ' + emh_worker.first_name as 'Worker'
From
emh_case_data_entity JOIN
dr_entity on dr_entity.entity_id = emh_case_data_entity.entity_id JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
emh_case_data_entity.field_id = dr_field.field_id
and dr_field.code = 'ir_2016_resdaysafe_12_12_3' join
emh_worker on emh_worker.worker_id = dr_entity.string_value )
as sorrw on sorrw.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_12_12_4')
as sortype on sortype.case_data_id = emh_case_data.case_data_id
LEFT JOIN
(SELECT emh_case_data_entity.case_data_id, dr_field_selection.string_value
From
emh_case_data_entity JOIN
dr_entity_selection on dr_entity_selection.entity_id = emh_case_data_entity.entity_id JOIN
dr_field_selection on dr_field_selection.selection_cd = dr_entity_selection.selection_cd JOIN
dr_field ON dr_field.field_id = emh_case_data_entity.field_id and
dr_field_selection.field_id = dr_field.field_id and dr_field.code = 'ir_2016_resdaysafe_12_12_5')
as yjsortype on yjsortype.case_data_id = emh_case_data.case_data_id
WHERE (dbo.emh_case_data.type_cd = 'ir_2016_resdaysafe') AND (dbo.emh_case_data.deleted IS NULL)
Irgendwelche Vorschläge, was der Fehler bezieht sich auf? Vielen Dank im Voraus .... Robert
reduzieren Sie das auf MVCE. Es gibt eine Menge nutzlosen Flaum drin. Beginnen Sie mit dem Ausreißen von Blöcken, bis der Fehler auftritt und Sie nichts mehr herausreißen können. –
Ich sehe eine Menge Präfixe auf Ihren Spalten, die keine entsprechende Tabelle in Ihrer Abfrage haben (zum Beispiel 'irlocation.string_value', wo ist die' location' Tabelle?) – Lamak
Ich habe nicht den gesamten Code (it hat die Frage nicht gestellt) .... Objekt hat eine entsprechende Unterabfrage ..... Ich kann die Unterabfrageblöcke für jedes Feld nicht reduzieren .... die Datenbank ist ein 3rd-Party-System, das ich nicht ändern kann ... und so speichern sie ihre Daten) - ich nehme nur das erste Bit auf .... Ich könnte die ganze Sache posten, wenn das hilft ..... –