Stored procedure help

  • You want to update instead of inserting, you you need to update data between 2 different tables?

  • What do you mean i dont understand i guess what are you saying.Can you be a little more clear please.

    THANKS

  • Please post sample data from all tables and the required output you need us to create.  SQL and data are universal language .

  • Values in the table TransactionCounts_Sort-sampledata

     ID     CalcAction                                          SortOrder

     1          Total Record Count                                     1

     2          Record Count of Unique Policies                     2

     3           Record Count by Status                              3

     

    Value in TransactionCounts-sample data

    ID  Month_of_file           CalcAction                  TableValue      CalculatedValue

    1      12/1/2004       Total Record Count                                   66476

     2      12/1/2004        Record Count of Unique Policies                   30356

     3     12/1/2004        Record Count by Status                A              66293

     4      12/1/2004        Record Count by Status               D              183

  • what i want to do is replace the values of CalcAction Column in TransactionCounts table with the values of CalcAction Column

    in the second table which is TransactionCounts_Sort

  • From the examples you give, and the question...I don't see what you are trying to do. You say you want to remove the values in the CalcAction column in the bottom table with the exact same values from the top table. That doesn't sound right.

    So, based on the two tables you showed us, what do you want the final result to look like?

    -SQLBill

  • Value in TransactionCounts- what iam looking for

    ID  Month_of_file           CalcAction                  TableValue      CalculatedValue

    1      12/1/2004               1                                                      66476

     2      12/1/2004               2                                                     30356

     3     12/1/2004                3                                     A              66293

  • Is the 'new' CalcAction based on the TransactionCounts_Sort.SortOrder or the TransactionCounts_Sort.ID?

    What do you want to have happen with the second Record Count by Status row?

    Something like:

    UPDATE TransactionCounts

    SET TransactionCounts.CalcAction = TransactionCounts_Sort.CalcAction

    FROM TransactionCounts, TransactionCounts_Sort

    WHERE TransactionCounts.ID = TransactionCounts_Sort.ID

    -SQLBill

  • it will show 3 in CalcAction column of transactioncount table.Dont you think i have to establish some sort of relationship between two tables such as primary key and foreign key

  • No. Not for a basic update like that. Primary/Foreign keys are for when you are inserting data and you need to maintain integrity of the data. You just said you want to update some data in one table.

    -SQLBill

Viewing 10 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply