![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
What is the best way of dealing with the null values in the TransactionsTable? |
|
I have two tables a master table and transaction table, the master table is updated by records in the transaction table. A simplification of the tables is below: CREATE TABLE [dbo].[MasterTable] ( [ContractID] [int] NOT NULL , [IName] [varchar] (50) COLLATE Latin1_General_CI_AS NULL , [Value1] [int] NULL , [Value2] [int] NULL , [Value3] [int] NULL , [Deleted] [bit] ) ON [PRIMARY] GO ALTER TABLE [dbo].[MasterTable] WITH NOCHECK ADD CONSTRAINT [PK_MasterTable] PRIMARY KEY CLUSTERED ( [ContractID] ) ON [PRIMARY] GO CREATE TABLE [dbo].[TransactionsTable] ( [ContractID] [int] NOT NULL , [TransactionType] [char] (1) COLLATE Latin1_General_CI_AS NOT NULL , [IName] [varchar] (50) COLLATE Latin1_General_CI_AS NULL , [Value1] [int] NULL , [Value2] [int] NULL , [Value3] [int] NULL ) ON [PRIMARY] GO The TransactionType is either 'U' or 'D' meaning Update or Delete. I plan to use a trigger on the TransactionsTable to update the MasterTable, when a transaction record is added to the TransactionsTable the record with the same ContractID in the MasterTable will be updated if a record doesn't exist it will be created. The Value* fields will contain a positive or negative integer and will be added to the value in the corresponding Value* field in the MasterTable. If the Value* field in the TransactionsTable contains a null then the corresponding Value* field in the MasterTable will not be updated, it will keep the same value. An Example: MasterTable Containing Records: 1,'test',5,6,7,0 After record below has been added to TransactionsTable: 1,'U','test name', 5,null,-7,0 The record in the MasterTable should be: 1,'test name',10,6,0,0 What is the best way of dealing with the null values in the TransactionsTable? In my actual tables I have 20 fields that need to be updated like this. Thank you in advance |
![]() |
| Thread Tools | |
| Display Modes | |
| |