Insert not working

Database
Enthusiast

Insert not working

I Have a master OLTP table A and Target table B (Built based on the source table A). The source table will get new data everymonth and i need to update the target table B using Insert (New Data) and update (modify existing) using the source data from A. So i am writing an Insert statement which should run every month which is not working..please help

Insert into TableB XX
(a,b,c,d,e,f......)
Select
A, CSUM(1,1),C,D,E,F.....
From TableA YY
where YY.A<>XX.A;

Also, please provide the code for update stattement.

4 REPLIES
Enthusiast

Re: Insert not working

Are you allowed to use merge? ???? when matched then ..when not matched then .....

Have a look at the syntax.

Cheers,

Teradata Employee

Re: Insert not working

Whats the error it throws?

Enthusiast

Re: Insert not working

The syntax is not right.

You can't define the alias for the target table mentioned in INSERT statement. On top of that you can't reference the target table (XX in your case) in SELECT clause!

I guess as suggested in the first reply, use the MERGE statement.

WAQ
Enthusiast

Re: Insert not working

Or else you can also use Left join on your key column (A in this case) to check whether the row already exist in your target or not (assuming from above SQL that you are only checking for "new data" case)