/****** SSMS 的 SelectTopNRows 命令的脚本 ******/
SELECT TOP (1000) [stud_id]
,[stud_name]
,[c1]
FROM [test01].[dbo].[student]
1.
declare @te int
declare @i int
declare c cursor
for (select stud_id from [student])
open c
fetch next from c into @i
while @@FETCH_STATUS=0
begin
set @te=(select c1 from [student] where stud_id=@i)
if @te is null
update [student] set c1= stud_id
else
update [student] set c1=5
FETCH NEXT FROM c INTO @i
end
close c
deallocate c
2. update student set c1=( case when c1 is null then stud_id else c1+'123' end)
sql update 根据条件更新
最新推荐文章于 2024-12-06 21:11:04 发布
本文介绍了一种使用SSMS (SQL Server Management Studio) 的方法来更新数据库表中的特定字段。通过示例展示了如何利用T-SQL脚本对student表中的c1字段进行条件更新,包括将空值替换为学生ID或给已有值添加特定字符串。
1227

被折叠的 条评论
为什么被折叠?



