如果在存储过程中调用另一个存储过程

比方说现在有一个时间表,如下:

要将上面这个时间表,处理完后的效果如下:

现在通过存储过程来实现这种效果的处理方法如下:
首先,处理英文月份的存储过程如下:

create procedure pro_DealDataTime
@month varchar(255),--月份参数
@result varchar(255) output --输出英文月份
as
set @result =
case
    
when @month = '1' then 'Jan'
    
when @month = '2' then 'Feb'
    
when @month = '3' then 'Mar'
    
when @month = '4' then  'Apr'
    
when @month = '5' then  'May'
    
when @month = '6' then 'Jun'
    
when @month = '7' then 'Jul'
    
when @month = '8' then 'Aug'
    
when @month = '9' then 'Sep'
    
when @month = '10' then  'Oct'
    
when @month = '11' then  'Nov'
    
else  'Dec'
end

GO

其次,通过创建一个用来处理日期的存储过程,如下:
CREATE procedure pro_Deal
as
declare @id int --定义ID
declare @date varchar(50)--保存日期vc_date列
declare @edate varchar(50)--保存日期vc_edate列
declare @year varchar(50)--保存年
declare @month varchar(50)--保存月
declare @emonth varchar(50)--保存英文月
declare mycursor cursor for select id,date_3 from tb_meet_2008  --定义一个游标mycursor
open mycursor --打开游标mycursor
fetch next from mycursor into @id,@date--开始抓第一条数据
while(@@fetch_status=0)--如果数据集中一直有数据
begin
    
set @year = substring(@date,1,4)
    
set @month = SUBSTRING(@date6CHARINDEX(''@date6- 6)
     
exec pro_DealDataTime @month,@emonth output;--调用另一个存储过程,@emonth既是返回的数据
         set @edate = @emonth+'-'+substring(@date,3,2)
         
insert into tb_date_2008(vc_date,vc_edate,i_year,i_month)values(@date,@edate,@year,@month)
        
end        
fetch next from mycursor into @id,@date --抓取下一条记录
end
close mycursor --关闭游标
deallocate mycursor --删除游标
GO

注意代码中这段 exec pro_DealDataTime @month,@emonth output;这句就是来调用另一个存储过程,
posted @ 2008-03-06 12:10  单车骑客  阅读(950)  评论(0编辑  收藏  举报