我有以下程序:
CREATE PROCEDURE [dbo].[meals] @EncounterID nvarchar(15), @EventDate nvarchar(30)
AS
DECLARE @TSQL varchar(8000);
SELECT @TSQL = 'SELECT * FROM OPENQUERY(cerner, ''select ce.result_val PercentEaten,
ce.event_cd Meal
from clinical_event ce
where
ce.task_assay_cd in ( 5362408, 5362296, 5361870)
and ce.event_end_dt_tm >= sysdate-30
and ce.event_cd in (636033, 636036, 636039)
and ce.event_class_cd = 233
and ce.encntr_id = ''' +CAST(@EncounterID as varchar(15))+ '''
and ce.event_end_dt_tm between to_char('''+CAST(@EventDate as varchar(30))+''' - .5) and
to_char('''+CAST(@EventDate as varchar(30))+''' - 1)
'')';
EXEC (@TSQL);
GO
当我使用这一行执行时:
exec dbo.meals @EncounterID = '12345678',@EventDate = '07/18/2013'
我收到一个错误,只是说error at line 9
我究竟做错了什么??