单个更新SQL查询中的列值增量

编程入门 行业动态 更新时间:2024-10-26 00:18:25
本文介绍了单个更新SQL查询中的列值增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的朋友们, 我遇到了与SQL查询相关的问题。我需要在单个更新查询的增量/减量中更新表列值(数据类型'int')。比如..第1列中的值为: - 第1列 1 2 3 4 。 。 。 结果应该是 第1栏 2 3 4 5 。 。 。 或 第1栏 0 1 2 3 。 。 。 谢谢

解决方案

DECLARE @ IncrementValue int SET @ IncrementValue = 1 UPDATE 表1 SET Column1 = Column1 + @ IncrementValue

听起来你需要SQL CURSORS。 看看这里的所有内容:游标(Transact-SQL) [ ^ ] 简而言之,使用游标,你可以循环遍历表的所有行,因此在循环中你可以修改值。

创建程序SP_Update_Points (@ SplID int,@ IncrPoints nvarchar(50)) As 开始 更新tblSpeciallists设置Points = CAST(Points as int)+ @ IncrPoints 其中SpeciallistID = @ SplID 结束 - 执行SP_Update_Points 1,3 - 使用此过程使用更新命令

在运行时增加列值

Dear Friends, I am facing a problem related to SQL query. I need to update a table column values (data type 'int') in increment/decrement on single update query. Like..there are values in column1 as:- Column1 1 2 3 4 . . . The result should be Column1 2 3 4 5 . . . OR Column1 0 1 2 3 . . . Thanks

解决方案

DECLARE @IncrementValue int SET @IncrementValue = 1 UPDATE Table1 SET Column1 = Column1 + @IncrementValue

Sounds like you need SQL CURSORS. Have a look here to read all about the: Cursors (Transact-SQL)[^] In a nutshell, using cursors, you can loop through all the rows of table and thus in the loop you can modify the values.

Create procedure SP_Update_Points (@SplID int,@IncrPoints nvarchar(50)) As Begin Update tblSpeciallists set Points=CAST(Points As int)+@IncrPoints where SpeciallistID=@SplID End --Exec SP_Update_Points 1,3 -- Use this procedure for increasing column value at runtime using Update command

更多推荐

单个更新SQL查询中的列值增量

本文发布于:2023-10-14 11:50:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1490975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:增量   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!