一:if else
語法: if 條件 begin 執行的操作 end else begin 執行的操作 end
二:while
語法:while 條件 begin 執行操作 end
實例:
USE [OABusiness] GO /****** 對象: StoredProcedure [dbo].[inertdate] 腳本日期: 08/31/2012 15:30:23 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE procedure [dbo].[inertdate] ( @date datetime , --插入的日期 @flag int --判定插入的數據 ) AS begin declare @count int;--用戶記錄條數 set @count=null; declare @count_add int ;--計數 set @count_add=1; declare @Userid int ;--用戶Userid set @Userid =NUll; declare @WorkHour int ;--插入的時間 declare @SignStatus int ;--狀態 end if @flag=0 begin set @WorkHour=0 set @SignStatus=1 end else if @flag=1 begin set @WorkHour=28800 set @SignStatus=0 end begin --獲取記錄條數 select @count=count(*) from dbo.T_UserInfo where Away_YN !=1 --循環插入記錄 while @count_add<@count+1 begin select @Userid=UserID from ( select row_number() over(order by UserID asc) as num,UserID,Away_YN from dbo.T_UserInfo where Away_YN !=1) as tem where num=@count_add insert into dbo.T_SigninStatistics (UserID,SignDate,WorkHour,SignStatus) values(@Userid,@date,@WorkHour,@SignStatus) set @count_add=@count_add+1 end end