一: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