
I want to write a Stored Procedure for these 2 tables ,
I have this SP but it doesn't achieve my point..
Code:
CREATE proc [dbo].[Sp_Insert]
@prdctName NVARCHAR(50),
@ordrdQnty INT,
@ordrPrice MONEY
--@TrnId INT
AS BEGIN TRAN
declare @TrnId int
set @TrnId = SCOPE_IDENTITY()
--IDENT_CURRENT
Insert into [OrderProduct]
(prdctName ,ordrdQnty ,ordrPrice,TrnId )
values (@prdctName,@ordrdQnty,@ordrPrice ,@TrnId)
declare @OrdrId int
declare @TrnTotal int
set @OrdrId=@@IDENTITY
--set @TrnTotal = @ordrPrice
--@ordrdQnty *
if @@ERROR<>0 goto ERR_
Insert into [Transaction] ( OrdrId,TrnDate )--,TrnTotal
values (@OrdrId,GETDATE() )--,@TrnTotal)
if @@ERROR<>0 goto ERR_
commit tran
return 0
ERR_:
rollback tran
return 1
GO
Comment