For sql-server
How can I insert a SKU row into table SKU_DATA
, then insert the SKU into INVENTORY
table with all branches and Quantity on hand=2 and Quantityonhand=0.
I need to insert a SKU item into SKUDATA and correspond row in inventory table for all existing branches Quantityonhand=2 and Quantityonhand = 0.
Please help Thanks
BRANCH
name varchar (30) not NULL,
managerNum INT NOT NULL,
SKU_DATA
SKU Int NOT NULL IDENTITY (1000,1),
description varchar (40) NOT NULL UNIQUE,
department varchar(30) NOT NULL default 'Home Entertainment',
sellingPrice numeric (7,2) NOT NULL ,
INVENTORY
SKU Int NOT NULL,
branch varchar (30) NOT NULL ,
quantityOnHand Int NOT NUll ,
quantityOnOrder Int NOT NUll ,
Procedure:
Create procedure InsertNewSkuWithInventory
@description varchar (40),
@department varchar(30),
@sellingPrice numeric (7,2),
AS
Declare @rowcount as int
Declare @SKU as int
Declare @branch as varchar(30)
Select @rowcount = COUNT(*)
from dbo.SKU_DATA
Where description = @description
And department = @department
And sellingPrice = @sellingPrice;
BEGIN
INSERT INTO dbo.SKU_DATA (description, department, sellingPrice)
VALUES (@description, @department, @sellingPrice);
Select @SKU =SKU
From dbo.SKU_DATA
Where description = @description
And department = @department
And sellingPrice = @sellingPrice;
DECLARE SKUCursor CURSOR FOR
SET @branch = @@IDENTITY
Select SKU
From dbo.inventory
Where
CLOSE SKUCursor
DEALLOCATE SKUCursor
END