Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Storing data in two tables ...

$
0
0
I want to store data in two tables using stored procedure but I've  faced problem , so I've tried to make something like this:
CREATE proc [dbo].[store]

(@TrnId int
,@prdctName nvarchar(50)
,@ordrdQnty int
,@ordrPrice money
,@OrdrId int
,@TrnDate datetime
,@TrnTotal money)

as
begin transaction trs

INSERT INTO [dbo].[OrderProduct]
(--[TrnId],
[prdctName]
,[ordrdQnty]
,[ordrPrice])
VALUES
(--( SELECT @@IDENTITY from [Transaction] ),
@prdctName
,@ordrdQnty
,@ordrPrice )

if @@ERROR<>0 goto Err_

INSERT INTO [dbo].[Transaction]
(
[OrdrId]
,[TrnDate]
,[TrnTotal])
VALUES
( @OrdrId ,CURRENT_TIMESTAMP ,@TrnTotal)

if @@ERROR<>0 goto Err_

commit tran
return 0

Err_:
rollback
return 1
============
but it doesn't work,
 Could  you help me please ....


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>