Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Update table based on ID reference comparing each column and value

$
0
0

Hi,

Through UI user can update any information and click save. In backend i will be receiving only ID as reference . Based on the ID value i should update multiple tables wherever i have the reference tables. Here i will not get the values or column name updated. I just get a ID to find which row is updated.

I should do a comparision now. 

I have a history table where i get the row before updation. and i get a row after updation from current data i.e. from ssdb_Railroad[This will be updated by java after updation we will get the ID inorder to update remaining tables]. Now i need to compare both the table column values and know which column is updated and after getting the value i should update reference tables.

Below is the structure for comparision table , History table and Main table.

Create table Comparision_History (
 ID   int IDENTITY(1,1) PRIMARY KEY,
 InsertUser_UpdateUser varchar(50),
 Old_ColVal  varchar(100),
 New_ColVal  varchar(100),
 TableName   varchar(100),
 [Action]     varchar(50),
 InsertDate_UpdateDate Datetime NOT NULL DEFAULT getdate()
 )

CREATE TABLE SSDB_Railroad_History (
    ID         int IDENTITY PRIMARY KEY,
SCAC       varchar(4) ,
Name       varchar(50) NOT NULL,
RailroadID int NOT NULL UNIQUE,
RC2Key  varchar(50),
NOTES      varchar(1000),
[Action]   varchar(50),
InsertDate_UpdateDate  Datetime NOT NULL DEFAULT getdate(),
InsertUser_UpdateUser  varchar(50),

)

CREATE TABLE SSDB_Railroad (
    ID   int IDENTITY(1,1)PRIMARY KEY,
SCAC varchar(4) UNIQUE,
Name varchar(50) NOT NULL,
RailroadID int NOT NULL UNIQUE,
RC2Key varchar(50),
InsertDate Datetime NOT NULL DEFAULT getdate(),
UpdateDate Datetime,
InsertUser varchar(50),
UpdateUser varchar(50)

)

Here SSDB_Railroad table and History table needs to be compared and get a updated value and it should be inserted in a comparision table. as well as it should be updated in reference tables.

Please help me with the code.

Thanks in Advance


Deepa



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>