I need to move data inserted from a holding table to individual tables based on a column in the holding data.
Eg. Holding table has a column CELL, which has values 1 thru 12.
There are 10 other tables CELL1 .. CELL12
The data in the holding table needs to be moved as \ after insertion into it. A trigger is a easy way, but how do I pass the parameters for specific table ?
Holding table
CREATE TABLE [dbo].[BANK1RAW](
[DTStamp] NOT NULL,
[PLCTime] NOT NULL,
[CellNumber] [int] NOT NULL,
[ReasonCode] [int] NOT NULL,
[Shift] [int] NOT NULL,
[CycleComplete] [bit] NOT NULL
) ON [PRIMARY]
CELL1
CREATE TABLE [dbo].[CELL1](
[DTStamp] NOT NULL,
[PLCTime] NOT NULL,
[ReasonCode] [int] NOT NULL,
[Shift] [int] NOT NULL,
[CycleComplete] [bit] NOT NULL
) ON [PRIMARY]
CELL2
CREATE TABLE [dbo].[CELL2](
[DTStamp] NOT NULL,
[PLCTime] NOT NULL,
[ReasonCode] [int] NOT NULL,
[Shift] [int] NOT NULL,
[CycleComplete] [bit] NOT NULL
) ON [PRIMARY]
SAMPLE DATA -
Insert into BANK1RAW Values (GetDate(), '2018-09-27 10:53:17.853', '1', '10','1', '1')
Insert into BANK1RAW Values (GetDate(), '2018-09-27 10:53:27.853', '2', '10','1', '1')
Insert into BANK1RAW Values (GetDate(), '2018-09-27 10:54:17.853', '2', '20','1', '1')
Insert into BANK1RAW Values (GetDate(), '2018-09-27 10:54:18.853', '2', '30','1', '1')
Insert into BANK1RAW Values (GetDate(), '2018-09-27 10:55:19.853', '1', '20','1', '1')
The idea is to move rows into its cell table as its inserted into the main table. Condition is CELL = 1 or CELL = 2. This example uses 2 cells, but I have 24 cells in the real application.
Thanks,
Mohit.