USE [ggg]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[Sp_InvDOItem]
(
@InvDOItemId int=null,
@IVDOno varchar(100)=null,
@Date datetime=null,
@ProductValue decimal(18,2)=null,
@Tax decimal(18,2)=null,
@GeneratedBy int =null,
@AssignedTo int=null,
@BookStockId INT =null,
@Status varchar(100)=null,
@InvoiceMode varchar(20)=null,
@Mode varchar(100),
@DetailsInvDOItemId int=null,
@ProductId int=null,
@Quantity decimal(18,2)=null,
@Quantity1 decimal(18,2)=null,
@BatchNo varchar(100)=null,
@BatchDate datetime=null,
@Denom_Value decimal(18,2)=null,
@Denom_Value1 decimal(18,2)=null,
@BatchItemDetailsId int=null,
@PartnerId int=null,
@Mode1 varchar(250)=null
)
as
begin
if(@Mode='INSERT')
BEGIN
INSERT INTO Tbl_InvDOItem(IVDOno,Date,ProductValue,Tax,GeneratedBy,AssignedTo,Status,InvoiceMode,IsActive)values(@IVDOno,@Date,@ProductValue,@Tax,@GeneratedBy,@AssignedTo,@Status,@InvoiceMode,'False')
SELECT IDENT_CURRENT('Tbl_InvDOItem')
END
if(@Mode='INSERTITEM')
BEGIN
INSERT INTO Tbl_DetailedInvDOItem(IvDonoId,ProductId,Quantity)values(@InvDOItemId,@ProductId,@Quantity)
SELECT IDENT_CURRENT('Tbl_DetailedInvDOItem')
END
IF(@Mode1='INSERTSTOCKBOOK')
BEGIN
INSERT INTO Tbl_StkBookStock(PartnerId,ProductId,Value)VALUES(@PartnerId,@ProductId,@Quantity1)
END
IF(@Mode1='UPDATESTOCKBOOK')
BEGIN
UPDATE Tbl_StkBookStock SET Value=@Quantity1 WHERE ProductId=@ProductId AND PartnerId=@PartnerId
END
IF(@Mode='INSERTBATCH')
BEGIN
INSERT INTO Tbl_BatchItemDetail(ItemDetailsId,BatchNo,BatchDate,Denom_Value,Quantity)values(@DetailsInvDOItemId,@BatchNo,@BatchDate,@Denom_Value,@Quantity)
END
if(@Mode='UPDATE')
BEGIN
UPDATE Tbl_InvDOItem SET IVDOno=@IVDOno,Date=@Date,ProductValue=@ProductValue,Tax=@Tax,GeneratedBy=@GeneratedBy,AssignedTo=@AssignedTo,Status=@Status,InvoiceMode=@InvoiceMode WHERE Itemdetailsid=@InvDOItemId
END
if(@Mode='UPDATEDO')
BEGIN
UPDATE Tbl_InvDOItem SET IVDOno=@IVDOno,Date=@Date,ProductValue=@ProductValue,Status=@Status,InvoiceMode=@InvoiceMode WHERE Itemdetailsid=@InvDOItemId
END
if(@Mode='ExitProductUPDATEITEM')
BEGIN
UPDATE Tbl_DetailedInvDOItem SET Quantity=@Quantity WHERE IvDonoId=@InvDOItemId and ProductId=@ProductId
SELECT IDENT_CURRENT('Tbl_DetailedInvDOItem')
END
if(@Mode='UPDATEUPDATEITEM')
BEGIN
UPDATE Tbl_DetailedInvDOItem SET IvDonoId=@InvDOItemId,ProductId=@ProductId,Quantity=@Quantity WHERE DIVitemId=@DetailsInvDOItemId
END
if(@Mode='UPDATEBATCH')
BEGIN
UPDATE Tbl_BatchItemDetail SET ItemDetailsId=@DetailsInvDOItemId,BatchNo=@BatchNo,BatchDate=@BatchDate,Denom_Value=@Denom_Value,Quantity=@Quantity WHERE Id=@BatchItemDetailsId
END
IF(@Mode1='insertbookstock')
begin
INSERT INTO Tbl_StkDetailedBookStock(BookStockId,Batchno,Date,DenomValue,Quantity)VALUES(@BookStockId,@Batchno,@BatchDate,@Denom_Value,@Quantity)
end
IF(@Mode1='UPDATEDETAILEDBOOKSTOCK')
BEGIN
UPDATE Tbl_StkDetailedBookStock SET DenomValue=@Denom_Value1,Quantity=@Quantity1 WHERE BookStockId=@BookStockId and BatchNo=@BatchNo and Date=@BatchDate
END
end
Hi this is my stored Procedure....anybody tell how to write Rollback and Commit Transaction because i want to save data in more than one table.