SELECT INTO SQL inside stored procedure

Database

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

3 REPLIES

Re: SELECT INTO SQL inside stored procedure

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
N/A

Re: SELECT INTO SQL inside stored procedure

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

Re: SELECT INTO SQL inside stored procedure

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.