找回密码
 注册账号

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

初学者课程:T3自学|T6自学|U8自学软件下载课件下载工具下载资料:通资料|U8资料|NC|培训|年结积分规则 | 使用常见问题Q&A
知识库:U8 | | NC | U9 | OA | 政务U8|U9|NCC|NC65|NC65客开|NCC客开新手必读 | 任务 | 快速增金币用友QQ群[微信群]
查看: 2318|回复: 3

[数据库知识] 果在存储过程中调用另一个存储过程

[复制链接]
发表于 2008-9-12 10:59:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册账号

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

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

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

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(@date, 6, CHARINDEX('月', @date, 6) - 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;这句就是来调用另一个存储过程,
发表于 2008-9-12 15:14:21 | 显示全部楼层
我还以为你这段存储过程出现问题了呢!
发表于 2008-9-13 10:46:46 | 显示全部楼层
学习一下你能告诉我一下你的联系方式吗?以后方便交流
发表于 2008-9-17 11:20:51 | 显示全部楼层
拿来参考参考。谢谢。
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|站长微信|Archiver|手机版|小黑屋|用友之家 ( 蜀ICP备07505338号|51072502110008 )

GMT+8, 2024-6-1 05:11 , Processed in 0.038147 second(s), 11 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表