Hi
I have 2 tables with the exact same structure. Table1 is a template table, Table2 is the CompItemRecord table.
The CompItemRecord table receives 1 datarow for each job item.
My condition is to add a new template record from Table1 INTO Table2 IF a CompItemRecord doesnt exist.
Table Structure - Table1
CREATE TABLE [dbo].[tbl_KLA_CompItemTemplate](
[comp_template_id] [int] IDENTITY(1,1) NOT NULL,
[job_id] [int] NOT NULL,
[item_id] [int] NOT NULL,
[rev_no] [int] NOT NULL,
[Description] varchar NOT NULL,
[PartNumber] varchar NOT NULL,
CONSTRAINT [PK_tbl_KLA_CompItemTemplate] PRIMARY KEY CLUSTERED
(
[comp_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
Table Structure - Table2
CREATE TABLE [dbo].[tbl_KLA_CompItem](
[comp_id] [int] IDENTITY(1,1) NOT NULL,
[job_id] [int] NOT NULL,
[item_id] [int] NOT NULL,
[rev_no] [int] NOT NULL,
[Description] varchar NOT NULL,
[PartNumber] varchar NOT NULL,
CONSTRAINT [PK_tbl_KLA_CompItem] PRIMARY KEY CLUSTERED
(
[comp_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
Im currently going through my VB.Net code to get the template row from Table1, store the values in a rangel or properties and sending it to Table2 Stored Procedure INSERT with a condition only to INSERT if the record currently doesnt exist and i do this as follows-
IF NOT EXISTS (SELECT [job_id], [item_id] FROM [dbo].[tbl_Table2] WHERE [job_id] = @job_id AND [item_id] = @item_id)
BEGIN
INSERT INTO
Question.
Is it possible to collect the row from Table1 by comp_template_id using a Stored Procedure and adding it to Table2 with the same condition as above without me doing this through the VB.Net class? Am i able to get the datarow and assign the values to the INSERT statement parameter values?
Thanks