Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张桌子叫Orders(Id,Number,ProductName).
Orders(Id,Number,ProductName)
我需要一个 SQL 命令,将列中的值减Number1。该Number列的类型为nvchar(50)。
Number
nvchar(50)
这是你要找的吗?
UPDATE Orders SET Number = Number - 1
SQL 小提琴演示
如果您的 Number 列中的某些值是非数字的,您可以使用 isumeric 来检查:
UPDATE Orders SET Number = Number - 1 WHERE IsNumeric(Number) = 1
更多小提琴
我想你想要:
Update Orders set Number = cast(cast((case when isnumeric(Number) = 1 then Number end) as int ) - 1 as nvarchar(50) )
仅仅因为一个列被调用Number,我不相信“数字”会一直在其中,除非我检查。如果它确实是一个数字,则将其声明为某种数字类型。