例如替换
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?
答案 0 :(得分:0)
不是100%肯定我明白你想要实现的目标。你想做这样的事吗?
declare @offset int
set @offset = 94
update BatchItem
set TransactionID = TransactionID + @offset
where BatchItemID = 123456
答案 1 :(得分:0)
试试这个:
UPDATE BatchItem SET TransactionId = TransactionId + 94
<强>更新强>
这似乎是@ Joe的答案的“快速和肮脏”版本。如果你发现它比他的答案更容易混淆,我会把它留下来......