All Forums Database
NewAmigo 27 posts Joined 02/14
13 Mar 2014
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, CSUM(1,1),C,D,E,F.....
From TableA YY
where YY.A<>XX.A;

Also, please provide the code for update stattement.

Raja_KT 1246 posts Joined 07/09
14 Mar 2014

Are you allowed to use merge? ???? when matched then ..when not matched then .....
Have a look at the syntax.

Raja K Thaw
My wiki:
Street Children suffer not by their fault. We can help them if we want.

Adeel Chaudhry 773 posts Joined 04/08
09 Apr 2014

Whats the error it throws?

-- If you are stuck at something .... consider it an opportunity to think anew.

Qaisar Kiani 337 posts Joined 11/05
10 Apr 2014

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 158 posts Joined 02/10
10 Apr 2014

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)

You must sign in to leave a comment.