Skip to Content
avatar image
Former Member

How to preserve the Calculation View data into a permanent table with primary key condition checking - using Stored Procedure

Hi,


How to preserve the Calculation View data into a permanent table using Stored Procedure.

Ex: Calculation View having Column1, Column2, Column3, Column4, Column5, Column6 Column7

In which Column1, Column2, Column3, Column4, Column5 makes Distinct (composite key)


Permanent Table having similar structure with columns & same data type of that calculation view

Columns : Column1, Column2, Column3, Column4, Column5, Column6 Column7

Primary key : Column1, Column2, Column3, Column4, Column5 (composite key)

How to preserve the Calculation view data into Permanent table without allowing duplicates.

If i used syntax like Select Columns from Calculation view into permanent table.

First time it entries but when 2nd time new records exists in calculation view, few data already exists in Permanent table in that time it will fail to insert because of primary key...

So it should update the data with Primary key condition, if it not exists then it should insert into permanent table.

& i also tried with UPSERT Statement but not getting correct result.

once i call the stored procedure, data has to pull out from calculation view, If exists it should update the records, else insert the new records into permanent table

Please suggest how to resolve this issue.

Thanks,

Thara


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 24, 2014 at 06:58 AM

    Hi Thara,

    Ideally UPSERT (UPDATE if keys match, INSERT otherwise ) should work for your scenario. If that is not working(may be you should re check the situation why it is not working), you can try this logic . Write a join statement with not equal condition for all the keys with CALCULATION VIEW and the TABLE. ( on CALC_VIEW.COLUMN1 != TABLE.COLUMN1 && ....) . This join would return you the difference of rows available. Then you can do a blind insert to your table . Performance wise, it is not good, but you can have a try here .

    Sree

    Add comment
    10|10000 characters needed characters exceeded