Solved

transform variables to sql

Posted on 2012-03-12
4
358 Views
Last Modified: 2012-03-30
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')))
0
Comment
Question by:sam2929
  • 2
4 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 37710608
could you explain a bit more ?
it's not clear what you are trying to do
0
 

Author Comment

by:sam2929
ID: 37711468
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')))
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 37720218
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
0
 
LVL 45

Accepted Solution

by:
Kdo earned 500 total points
ID: 37724804
Hi Sam,

The end time is built from the current Julian date and current time.  Current Timestamp should be a suitable substitute and not require the hoops that the code is jumping through.

The start time is read from the database (aaSTG_DELTA_TIMESTAMPS).  Simply substituting that query into the filter is equivalent to computing a variable and using the var.

WHERE (((aa.new.GEO IN ('aa', 'bb')
  AND (aaSTG_MATCHES.MATCH_TIMESTAMP >= (SELECT starttime FROM aaSTG_DELTA_TIMESTAMPS
                                         WHERE PROCESSKEY = 'Export Responses to MII')))
  AND (aaSTG_MATCHES.MATCH_TIMESTAMP < current_timestamp))
  AND (aaSTG_MATCHES.MATCH_TYPE <> 'cc')))

Open in new window


Does that solve things?
Kent
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now