vb Code:
Use MasterFile
GO
If EXISTS(SELECT name FROM sysobjects
WHERE name='StockInTest3')
DROP PROCEDURE StockInTest3
GO
CREATE PROCEDURE StockInTest3
@ProdID varchar(50),
@ProdName varchar(50),
@EntryDate datetime,
@ProdUnit varchar(50),
@ProdReorderPoint int,
@ProdPurchasePrice money,
@ProdQTY int
AS
DECLARE @MaxSEQ INT
DECLARE @ProdCount INT
BEGIN TRAN
-- SELECT @ProdCount = COUNT(ProductID)
-- FROM tblStockMasterFile
-- WHERE ProductID = @ProdID
SET @MaxSEQ=(SELECT IsNull(Max(pSequence),0 )+ 1
FROM tblStockTransFile
WHERE ProductID= @ProdID AND EntryDate=@EntryDate)
--print @MaxSeq
---- INSERT INTO tblStockMasterFile (ProductID, ProductName, Unit, ReOrderPoint)
---- VALUES(@ProdID, @ProdName, @ProdUnit, @ProdReOrderPoint)
If Not Exists(Select * From tblStockMasterFile Where ProductId=@ProdId)
Begin
INSERT INTO tblStockMasterFile (ProductID, ProductName, Unit, ReOrderPoint)
VALUES(@ProdID, @ProdName, @ProdUnit, @ProdReOrderPoint)
End
--select * from tblStockMasterFile Where PRoductId=@ProdId
Declare @ErrorCode int
-- IF @ProdCount <> 0
INSERT INTO tblStockTransFile (ProductID, EntryDate, PurchasePrice, Quantity, Reason, pSequence)
VALUES(@ProdID, @EntryDate, @ProdPurchasePrice, @ProdQTY, 'In', @MaxSEQ)
Set @ErrorCode=@@ERROR
print @ERRORCODE
select * From tblStockTransFile Where ProductId=@ProdId
IF @ERRORCODE = 0
COMMIT
ELSE
ROLLBACK
--ROLLBACK -- temporarily rollback always for testing purposes
Next step is I will call this in vb