I want to declare two variable and use thoes variable in where condition of a select statement in teradata, but I am getting an error in that.
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;