在 SQL 中用不同范围的数字替换一定范围的数字
例如分别替换
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?
For example replace
TransactionID
--------
1
2
3
with
TransactionID
--------
95
96
97
respectively. Basically, I want to replace numbers with numbers but for multiple items without writing update statement for each item.
Example:
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**
How do I write above statement to update multiple transactionID in sequence?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不能100%确定我理解你想要实现的目标。你想做这样的事情吗?
Not 100% sure I understand what you're trying to achieve. Are you trying to do something like this?
试试这个:
更新
这似乎是@Joe 答案的“快速而肮脏”的版本。如果您发现它没有他的答案那么令人困惑,我会保留它......
Try this:
UPDATE
This appears to be the "quick and dirty" version of @Joe's answer. I'll leave it up in case you find it less confusing than his answer...