我在变量中输入了一个数字,例如:
svg {
overflow: visible !important;
}
.cont {
position: absolute;
top: 0;
left: 0;
}
svg .main-path {
fill: none;
stroke-width: 5px;
stroke: steelblue;
}
.invalid {
width: 1px;
height: 1px;
}
.invalid .main-path {
stroke: red;
}
因此,假设我们在此变量中输入了数字DECLARE @CurrentLastFolio INT = (SELECT TOP 1 Folio FROM myTable ORDER BY folio DESC)
。
在另一个查询中,我有一些1004
行:
folio = 0
我要做的是用每行SELECT * FROM myTable WHERE folio = 0
更新此记录。因此,第一行的Folio = 1005,下一个1006,依此类推。
我该如何实现?
答案 0 :(得分:2)
您可以使用以下解决方案,也可以更新UPDATE
上的变量:
DECLARE @CurrentLastFolio INT = (SELECT MAX(folio) FROM table_name);
UPDATE table_name
SET folio = @CurrentLastFolio, @CurrentLastFolio += 1
WHERE folio = 0
将表达式转换为数据类型int的算术溢出错误:
如果您的值大于2,147,483,647(INT
数据类型的最大值),则需要使用BIGINT
的{{1}}整数来存储(列INT
)或递增值(变量folio
):
@CurrentLastFolio
答案 1 :(得分:1)
检查:
declare @CurrentLastFolio int = (SELECT TOP 1 Folio from myTable order by folio desc);
with tbl AS
(
SELECT * ,ROW_NUMBER() OVER( order by c1 ) AS rn
FROM myTable
)
update tbl set folio = rn + @x
示例实现,易于理解
create table t (c1 int); GO
✓
insert into t values (1), (2), (3) GO
3 rows affected
declare @x int = 1000; with tbl AS ( SELECT * ,ROW_NUMBER() OVER( order by c1 ) AS rn FROM t ) update tbl set c1 = rn + @x GO
3 rows affected
select * from t GO
| c1 | | ---: | | 1001 | | 1002 | | 1003 |
db <>提琴here