asp.net - How to use SELECT in sqlcommand -
i have 2 tables
table payment:
paymentid orderid{fk_payment_orderlist} totalprice datetime status refid salereferenceid
table orderlist:
orderid customerid classid
i have storedprocedure :
use [miztahrirtest2] go /****** object: storedprocedure [dbo].[insertpayment] script date: 8/19/2015 8:51:08 pm ******/ set ansi_nulls on go set quoted_identifier on go alter procedure [dbo].[insertpayment] @orderid int,@totalprice int,@status nvarchar(50),@new_identity int output begin insert payment(orderid,totalprice,[datetime],[status],refid,salereferenceid) select max(orderid) orderlist orderid,values(@orderid,@totalprice,getdate(),@status,'','') select @new_identity = scope_identity() select @new_identity id return @new_identity end
i want choose last orderid
orderlist
table , set in values payment
table code doesn't work correctly .what should now?
you need define orderid field identity, automatically handled , should remove insert statement. can use scope_identity() id value row inserted got.
so insert statement should this:
insert payment(totalprice,[datetime],[status],refid,salereferenceid) values(@totalprice,getdate(),@status,'','')
Comments
Post a Comment