Using While Loop for SQL Server Update

后端 未结 3 1938
青春惊慌失措
青春惊慌失措 2021-01-16 12:49

I am trying to become more efficient in my SQL programming. I am trying to run a loop to repeat an update command on field names that only change by a numerical suffix.

3条回答
  •  长情又很酷
    2021-01-16 13:04

    while @count < @countOfSession
    begin
      if @day = 'Saturday' or @day = 'Tuesday'
      begin
        if @day='Saturday'
        begin
          select @date
          set @day='Tuesday'
          set @count=@count+1
          set @date=@date+3
        end
        else if @day='Tuesday'
        begin
          select @date
          set @day='Saturday'
          set @count=@count+1
          set @date=@date+4
        end
      end
    end
    

提交回复
热议问题