0

例如替换

TransactionID
--------
 1
 2
 3 

TransactionID
--------
 95
 96
 97

分别。基本上,我想用数字替换数字,但是对于多个项目,而不为每个项目编写更新语句。

例子:

Update BatchItem
    set TransactionID = '95'
    where BatchItemID = 12345**6**


Update BatchItem
    set TransactionID = '96'
    where BatchItemID = 12345**7**


Update BatchItem
    set TransactionID = '97'
    where BatchItemID = 12345**8**

如何编写上述语句以按顺序更新多个 transactionID?

4

2 回答 2

0

尝试这个:

UPDATE BatchItem SET TransactionId = TransactionId + 94

更新

这似乎是@Joe 答案的“快速而肮脏”的版本。如果您发现它比他的回答更令人困惑,我会保留它...

于 2010-12-14T21:50:09.780 回答
0

不是 100% 确定我理解你想要达到的目标。你想做这样的事情吗?

declare @offset int
set @offset = 94

update BatchItem
    set TransactionID = TransactionID + @offset
    where BatchItemID = 123456
于 2010-12-14T21:47:30.263 回答