日期:2014-05-17 浏览次数:20585 次
USE [TSMISData] GO /****** Object: StoredProcedure [dbo].[ontime] Script Date: 09/28/2012 10:55:18 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER proc [dbo].[ontime] @begintime datetime, @endtime datetime, @ontmie_day int as declare @ERROR varchar(60) declare @tbl table(id int identity(1,1) primary key , dayname varchar ) begin if len(@begintime)=0 or LEN(@endtime)=0 begin set @ERROR='输入的日期时间不能为空' end if ISDATE(@begintime)=0 or ISDATE(@endtime)=0 begin set @ERROR='您输入的时间格式有误!' return 1 end else begin while @begintime>@endtime begin insert @tbl(dayname)values(@begintime); set @begintime=@begintime+1; end end select @ontmie_day=COUNT(dayname) from @tbl where dayname not in ('星期六','星期日') return @ontmie_day end
ALTER proc [dbo].[ontime] @begintime datetime, @endtime datetime, @ontmie_day INT OUTPUT -- -1表示您输入的时间格式有误,-2表示输入的日期时间不能为空,大于0表示有记录 as begin declare @tbl table(id int identity(1,1) primary key , [dayname] varchar ) if len(@begintime)=0 or LEN(@endtime)=0 begin set @ontmie_day = -2 RETURN END if ISDATE(@begintime)=0 or ISDATE(@endtime)=0 begin set @ontmie_day = -1 RETURN end else begin while @begintime>@endtime begin insert @tbl(dayname) values(@begintime); set @begintime=@begintime+1; end END select @ontmie_day=COUNT(dayname) from @tbl where [dayname] not in ('星期六','星期日') end
------解决方案--------------------
把需要输出的变量(存储过程的参数)加output