我想声明两个变量并在 teradata 中的 select 语句的 where 条件中使用 thoes 变量,但我得到了一个错误。
Create Procedure Demo()
Begin
Declare REnd Date;
Declare RStart Date;
Set REnd = (select max(CalendarDate) as REnd
from Table1
where CalendarDate = MonthEndDate
and Monthofyear in ('June', 'December')
and CalendarDate < Current_date()
);
Set RStart = (select max(CalendarDate) as RStart
from Table1
where CalendarDate = (CalendarDate - Extract(Day From CalendarDate)+1)
and Monthofyear in ('January', 'July')
and CalendarDate < REnd
);
Call dbc.sysexecsql(('select * from table 2 where reviewdate between' ||REnd|| 'and' ||RStart|| ');');
End;