All Forums Database
davidRC 2 posts Joined 10/13
08 Oct 2013
SELECT INTO SQL inside stored procedure

Hi All,
I have the following SQL inside a stored procedure file and need some help.  I don't have access to the database so I can't test it out.

SELECT ZEROIFNULL(last_load_batch_sk) (TITLE '')
FROM   ica_app.md_aggregate_batch INTO ln_last_load_billing
WHERE process_sk= 213;

Is this valid SQL? I've never seen a SELECT INTO statement with the FROM clause preceding the INTO clause.  Is this just a Teradata thing? Also, I don't understand what the (TITLE '') part is doing at the end of the first line.  Any help is appreciated.
Thanks,
David

M.Saeed Khurram 544 posts Joined 09/12
08 Oct 2013

Title is used to rename a column in Teradata, and it is Teradata extention. following is the syntax of Teradata for INSERT-SELECT.

INSERT INTO ln_last_load_billing
SELECT ZEROIFNULL(last_load_batch_sk) (TITLE '')
FROM   ica_app.md_aggregate_batch 
WHERE process_sk= 213;

 

Khurram

dnoeth 4628 posts Joined 11/04
08 Oct 2013

Hi David,
it's valid Teradata SQL :-)
This is based on some really old syntax (before Standard SQL), when you correctly start with the first keyword (SELECT/DELETE/etc.) you can write in non-standard order, the parser accepts that without error, e.g.
SELECT ... ORDER BY ... HAVING ... WHERE 
You usually just don't notice that because you're used to do it the right way.
 
Dieter

Dieter

davidRC 2 posts Joined 10/13
09 Oct 2013

Thanks for the clarification guys. This has been really helpful. I suppose this is what my buddy meant when he said that Teradata SQL is really ambiguous. 

You must sign in to leave a comment.