Skip to content
+1-888-319-3663

COMMUNITY FORUM

Use Global variable in where clause

Dan asked 2 years ago
All,
Could we use the Global Run date as a comparision to the GP timestamp in GP to grab any new items from last run time in Select stmt for source:
Select * from table where dex row time stamp > Global run date 
Thank you,
Answers
Patrick Roth Staff answered 2 years ago
I don’t see why you couldn’t use that variable in your source query.  In the end, the variable is just replaced with the actual data.  So as long as SQL is cool with the date formatting we return then your query would be valid.
That said, I don’t see how that exact query could work.  Since by definition, “GlobalRunDate” is right now, then all of the records in <table> would have to be older than that time (since the DEX_ROW_TS would never be future from now unless different timezone since GP doesn’t track time zone info).
You’d have to do something then to manipulate that datetime by using the TSQL to ADDDATE and subtract Hours or Minutes from that GlobalRunDate.
I guess, too, that if we accept that GlobalRunDate is “now” by definition, you could as well use the SQL GetDate() and you can avoid SC having to replace GlobalRunDate with that variable for execution.

If you would like to submit an answer or comment, please sign in to the eOne portal.