All Forums Tools
aaibinder 9 posts Joined 08/16
22 Aug 2016
TPT Script, Only Pull Entries Within Last 6 Months?

So my original query in Sqoop was included the condition
 
BROADCAST_DT > DATE - INTERVAL '6' MONTH
 
I've been trying to put this into my TPT script, inside the SelectStmt attribute.
 
This is my first time using TPT, and first 2 weeks using Teradata, so please forgive if I'm asking a stupid question...
My current Select statement is...
 
SelectStmt = 'SELECT * FROM dbname.tablename WHERE ENTRY_ID = 30', 
I keep trying to add in the BROADCAST_DT > DATE - INTERVAL '6' MONTH condition, but I can't figure out how.
 
If I do it like...
SelectStmt = 'SELECT * FROM dbname.tablename WHERE ENTRY_ID = 30 AND BROADCAST_DT > DATE - INTERVAL '6' MONTH'
The first ' in '6' ends the string.
If I try switching it to...
"SELECT * FROM dbname.tablename WHERE ENTRY_ID = 30 AND BROADCAST_DT > DATE - INTERVAL '6' MONTH"
That doesn't work.
'SELECT * FROM dbname.tablename WHERE ENTRY_ID = 30 AND BROADCAST_DT > DATE - INTERVAL "6" MONTH'
Is also a failure.
As is...
'SELECT * FROM dbname.tablename WHERE ENTRY_ID = 30 AND BROADCAST_DT > DATE - INTERVAL \'6\' MONTH'
Even tried using ` symbols. They all created errors. Any ideas?

feinholz 1234 posts Joined 05/08
22 Aug 2016

SQL statements assigned to attributes are enclosed in single-quotes.
Because of this, all single-quotes inside that string must be escaped (doubled) in order to be preserved.
 
So, your SelectStmt would be:
 
'SELECT * FROM dbname.tablename WHERE ENTRY_ID = 30 AND BROADCAST_DT > DATE - INTERVAL ''6'' MONTH;'
 
Make sure you use 2 single-quotes and not a double-quote character.

--SteveF

aaibinder 9 posts Joined 08/16
23 Aug 2016

Thanks!

You must sign in to leave a comment.