TPT Script, Only Pull Entries Within Last 6 Months?

Tools
Enthusiast

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?

2 REPLIES
Teradata Employee

Re: TPT Script, Only Pull Entries Within Last 6 Months?

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
Enthusiast

Re: TPT Script, Only Pull Entries Within Last 6 Months?

Thanks!