基本上,我正在尝试创建一个向我发送电子邮件警报的 T-SQL 语句。我附上了下面的查询。查询从 select 开始,在 Tat 0 结束,这是我想要执行并通过电子邮件返回这些数据的内容。
当我单独运行该查询时,它会很好地返回它。我怀疑它在整个 T-SQL 语句中的某些内容不正确。我有点像 db newb。任何澄清都会非常有帮助。
begin
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'TRGEmail',
@recipients = 'test@test.com',
@body = 'The cases below have reach TAT 3 for PRI X Ray. Please set accordingly.
',
@query = 'select
PATIENTS.FirstName, PATIENTS.Lastname,
STUDIES.study_datetime,
STUDY_LIST_VIEW.tat,
PATIENTS.Patient_ID
from
opalrad.dbo.INSTITUTIONS INSTITUTIONS,
opalrad.dbo.PATIENTS PATIENTS,
opalrad.dbo.STATUSES STATUSES,
opalrad.dbo.STUDIES STUDIES,
opalrad.dbo.studies_calc studies_calc,
opalrad.dbo.STUDY_LIST_VIEW STUDY_LIST_VIEW,
opalrad.dbo.TRANSCRIPTION_TEXT TRANSCRIPTION_TEXT
where
STUDIES.study_id = studies_calc.study_id AND
STUDIES.institution_id = INSTITUTIONS.institution_id AND
TRANSCRIPTION_TEXT.STUDY_ID = STUDIES.study_id AND
TRANSCRIPTION_TEXT.STUDY_ID = studies_calc.study_id AND
PATIENTS.Patient_ID = STUDIES.patient_id AND
STUDY_LIST_VIEW.INSTITUTION_ID = INSTITUTIONS.institution_id AND
STUDY_LIST_VIEW.PATIENT_ID = PATIENTS.Patient_ID AND
STUDY_LIST_VIEW.study_id = STUDIES.study_id AND
STUDY_LIST_VIEW.study_id = studies_calc.study_id AND
((INSTITUTIONS.institution_id= 569 ) AND
(STUDY_LIST_VIEW.tat=0))',
@subject = 'PRI STAT 3 requiring attention';
end