Avatar of sam2929
sam2929
 asked on

transform variables to sql

Hi,
i have two variables which are not passed in sql right now i want to get rid of that variables and pass them direct to sql how can i do that



v= DATE_STRING(CURRENT_JULIAN()-7, YYYYMMDD);

UserVar.DELTA_EndTime = STRING_concat(
     substr(v,1,4), '-',
     substr(v, 5,2), '-',
     substr(v,7,2), ' ',
     CURRENT_TIME())

UserVar.DELTA_StartTime is
select starttime from aaSTG_DELTA_TIMESTAMPS
where PROCESSKEY = 'Export Responses to MII'
with ur;

sql is

WHERE (((aa.new.GEO IN ('aa', 'bb')
                 AND (aaSTG_MATCHES.MATCH_TIMESTAMP >=
                         UserVar.DELTA_StartTime))
               AND (aaSTG_MATCHES.MATCH_TIMESTAMP < UserVar.DELTA_EndTime))
             AND (aaSTG_MATCHES.MATCH_TYPE <> 'cc')))
DB2

Avatar of undefined
Last Comment
Kent Olsen

8/22/2022 - Mon
momi_sabag

could you explain a bit more ?
it's not clear what you are trying to do
sam2929

ASKER
I want to replace the varaible

currently WHERE (((aa.new.GEO IN ('aa', 'bb')
                 AND (aaSTG_MATCHES.MATCH_TIMESTAMP >=
                         UserVar.DELTA_StartTime))
               AND (aaSTG_MATCHES.MATCH_TIMESTAMP < UserVar.DELTA_EndTime))
             AND (aaSTG_MATCHES.MATCH_TYPE <> 'cc')))

wants

WHERE (((aa.new.GEO IN ('aa', 'bb')
                 AND (aaSTG_MATCHES.MATCH_TIMESTAMP >=
                         select starttime from aa.STG_DELTA_TIMESTAMPS
where PROCESSKEY = 'Export Responses to MII'))
               AND (aaSTG_MATCHES.MATCH_TIMESTAMP < UserVar.DELTA_EndTime))
             AND (aaSTG_MATCHES.MATCH_TYPE <> 'cc')))
momi_sabag

you want to use dynamic sql then?
something like
set var = 'WHERE (((aa.new.GEO IN ('aa', 'bb')
                 AND (aaSTG_MATCHES.MATCH_TIMESTAMP >= ' ||
                         UserVar.DELTA_StartTime || '))
               AND (aaSTG_MATCHES.MATCH_TIMESTAMP < UserVar.DELTA_EndTime))
             AND (aaSTG_MATCHES.MATCH_TYPE <> 'cc')))'

execute immediate var
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Kent Olsen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.