0

我在以这种方式插入数据时遇到了问题。

在此处输入图像描述

如何使用存储过程以这种方式插入数据。

INSERT INTO [dbo].tbl_Transaction                
        (                
             [FK_GameID] ,            
             [SpotID] ,            
             TransactionReason ,            
             TransactionType ,            
             TransactionAmount
             --PrevAmountBalance,
            -- CurrentBalance
        )                
       SELECT tblTransaction.Row.value('@FK_GameID','BIGINT'),            
       tblTransaction.Row.value('@SpotID','SMALLINT'),            
       tblTransaction.Row.value('@TransactionReason','SMALLINT'),            
       tblTransaction.Row.value('@TransactionType','Varchar(50)'),            
       tblTransaction.Row.value('@TransactionAmount','MONEY')
       --@OpeningBalance,
       -- (@OpeningBalance-tblTransaction.Row.value('@TransactionAmount','MONEY'))
       FROM @TransactionTable.nodes('/row') AS tblTransaction(Row)   
4

1 回答 1

0
create table #balances(
id int not null identity(1,1),
opening_balance int, 
closing_balance int, 
t_type varchar(50))

启动表(如果你没有这个,你将不得不处理 NULL)

insert into #balances values (100 , 100 , 'start')

询问:

insert into #balances values(
(select top 1 closing_balance from #balances order by id desc),
300, --new value
'credit')
于 2012-04-05T14:44:48.060 回答