2016-07-25 134 views
-1

我寫過一個查詢,它在SSMS中作爲select語句運行良好,但是當我嘗試將它保存爲視圖時,出現錯誤窗口用「附近有語法錯誤工人',‘AS’關鍵字附近的語法不正確,(重複該線,直到它只是表明該行的第一個6個字符在對話框的底部。'Worker'附近的語法錯誤,關鍵字'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) 

任何關於錯誤是指什麼的建議??? 非常感謝提前... 羅伯特

+0

減少到mvce。那裏有很多無用的絨毛。開始剝離塊,直到錯誤發生,沒有什麼可以撕掉。 –

+1

我在你的列中看到很多在你的查詢中沒有對應表的前綴(例如'irlocation.string_value','irlocation'表?') – Lamak

+0

我沒有包含所有的代碼(它沒有發佈的問題)....對象有一個相應的子查詢.....我不能減少每個領域的子查詢塊....數據庫是我不能改變的第三方系統...這就是他們如何存儲他們的數據) - 我只是包括第一位....我可以發佈整個事情,如果有幫助..... –

回答

0

對於初學者,你有一個額外的逗號,一個'YJ SOR Type'... FROM

.... 
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 
.... 
+0

Oopps ...對不起..我刪除了一個塊和一個字段,因爲我的帖子超過了大小限制..在那裏不應該有一個逗號....我的原始查詢在列的最後一部分之後沒有逗號.... –

+0

更新:所以我已經能夠使用語法從我的選擇查詢中創建一個視圖,但2016和2014年SSMS上的圖形用戶界面都給出了相同的錯誤保存.....相當奇怪.....但我能夠讓他們進入sql服務器。 –

相關問題