First I have insert the data from bb_IssueReq table to @transaction , after that i want update the multiple row based on selected SQL query trans_id . Now the result only can update the single row. do you have any suggestion to improve the SQL query for update the multiple row in @transaction. The SQL query was attached below.
DECLARE @transaction table (
id bigint,invoice_no varchar(50),[time] datetime,
trans_id bigint,cust_hp varchar(50),
cardno varchar(20),username varchar(200),
bb_value money,bb_amount money,
key_amt money, charge money,
bb_type int,pay_amt money
)
INSERT INTO @transaction
(id, invoice_no, [time], trans_id, cust_hp, cardno, username,
bb_value, bb_amount, key_amt, charge)
SELECT top 20
id as issue_idx,
invoice_no as [invoice_no],
Updated as [timestamp],
id as trans_id,
hp as cust_hp,
card_no as cardno,
name as username,
b_value as bb_value,
amount as bb_amount,
Amount as key_amt,
charr as charge,
FROM bb_IssueReq(NOLOCK)
where status = 0 and id ='1211'
declare @trans bigint, @bbtype int, @payout money
SELECT top 20
@trans =A.trans_id,
@bbype =B.type,
@payout =Cast(C.amt * C.rate)
FROM bb_IssueReq(NOLOCK) A
inner join vw_req B on A.trans_id = B.id
inner join trant C on C.payroll_tranid = B.redeem_id
where A.status = 0 and A.id = '1211'
********* update query based on @trans *********
update @transaction
set bb_type = @bbtype,
pay_amt = @payout
where trans_id = @trans
select * from @transaction