当前位置:   article > 正文

SQLSERVER 遍历循环的两种方式很详细有源码(1)_sql循环遍历查询

sql循环遍历查询

1.普通循环

Create table WS_Student
(
      [Id] int primary key not null,
    [My_Cocode] [int],
    [My_SCocode] [int],
    [userId] [bigint],
    [SetCName] [varchar](50) NULL,
    [SetEName] [varchar](50) NULL,
    [SetPcode] [varchar](50) NULL,
    [SetScode] [varchar](50) NULL,
    [SetValue] [varchar](50) NULL,
    [SetSql] [varchar](500) NULL,
    [Sort] [Int] NULL,
    [IsTurnOn] [bit] NULL,
    [IsSystem] [bit] NULL,
    [Remarks] [varchar](50) NULL,
    [CreatedUserId] [bigint] NULL,
    [CreatedUserName] [varchar](50) NULL,
    [CreatedTime] [datetime] NULL,
    [UpdatedUserId] [bigint] NULL,
    [UpdatedUserName] [varchar](50) NULL,
    [UpdatedTime] [datetime] NULL,
    [IsDeleted] [bit] NULL
)
INSERT INTO WS_Student VALUES(1,21114001,21114005,0,'是否学生','是否学生','WS_Student',
'WS_Student_IsStudent','1',null,1,1,1,'是否学生',999999,'shil',GETDATE(),999999,'shil',GETDATE(),0)

INSERT INTO WS_Student VALUES(2,21114001,21114005,0,'是否学生2','是否学生2','WS_Student',
'WS_Student_IsStudent2','1',null,1,1,1,'是否学生2',999999,'shil',GETDATE(),999999,'shil',GETDATE(),0)

--循环5次来新增学生表信息

--循环遍历修改记录--
declare @i int  
set @i=7
while @i<9
begin
    INSERT INTO WS_Student VALUES((@i,21114001,21114005,0,'是否学生','是否学生','WS_Student',
'WS_Student_IsStudent','1',null,1,1,1,'是否学生',999999,'shil',GETDATE(),999999,'shil',GETDATE(),0)
    set @i=@i +1
end
--查看结果--
select * from WS_Student

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/409828
推荐阅读
相关标签
  

闽ICP备14008679号