如何调用SQL2000 自定义函数

mzcih 2008-04-14 04:55:21
相关网址:http://topic.csdn.net/u/20080409/16/1fb7d941-b1a1-4326-a936-230ddf057cbe.html

详细代码如下:
create table AAA(ID INT,strNum1 varchar(8),strNum2 varchar(8),intTaxis int)
insert into AAA select 1,'01' ,'001',1
insert into AAA select 2,'001','011',2
insert into AAA select 3,'001','010',1
insert into AAA select 6,'01' ,'002',2
insert into AAA select 4,'002','021',1
insert into AAA select 5,'002','022',2
go

create function f_getChild(@strNum1 VARCHAR(10))
returns @t table(strNum1 VARCHAR(10),strNum2 VARCHAR(10),Level INT,Ord varchar(100))
as
begin
declare @i int
set @i=1
insert into @t select strNum1,strNum2,@i,right('0'+strNum2,3) from AAA where strNum1 = @strNum1

while @@rowcount<>0
begin
set @i=@i+1
insert into @t
select
a.strNum1,a.strNum2,@i,b.Ord+a.strNum2
from
AAA a,@t b
where
a.strNum1=b.strNum2 and b.Level=@i-1
and
not exists(select 1 from @t where strNum1=a.strNum1 and strNum2=a.strNum2)
end
return
end
go

select * from dbo.f_getChild('01') order by Ord
go


strNum1 strNum2 Level Ord
---------- ---------- ----------- -----------
01 001 1 001
001 010 2 001010
001 011 2 001011
01 002 1 002
002 021 2 002021
002 022 2 002022

drop function f_getChild
drop table AAA
go

问题是ASP里面如何调用select * from dbo.f_getChild('01') order by Ord这句并显示呢?
...全文
169 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
myvicy 2008-04-14
  • 打赏
  • 举报
回复
直接在asp调用"select * from dbo.f_getChild('01') order by Ord"就可以。
lin335 2008-04-14
  • 打赏
  • 举报
回复
著名培训公司最新 ajax、php5.0、linux(包括系统管理、网络管理、高级应用、Oracle + Weblogic安装配置等)
.net软件工程师培训 共50G左右 联系QQ 9 3 6 6 5 2 1 1 4
mzcih 2008-04-14
  • 打赏
  • 举报
回复
谢谢大家的帮忙,我试下先。
gingerkang 2008-04-14
  • 打赏
  • 举报
回复
你的函数是返回表的数据集合,如4#,跟查表或视图一样调用就行了.
Atai-Lu 2008-04-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 beyondamane 的回复:]
直接在sql语句里面这么写就可以调用了:select * from dbo.f_getChild('01') order by Ord
[/Quote]
zl_c 2008-04-14
  • 打赏
  • 举报
回复
改成存储过程,用ASP调用这个存储过程,取得记录集.
CREATE   PROCEDURE [f_getChild]
(
@strNum1 VARCHAR(10)
)

as
begin
declare @t table
(
[strNum1] [VARCHAR] (10),
[strNum2] [VARCHAR] (10),
[Level] [INT],
[Ord] [VARCHAR] (100)
)
declare @i int
set @i=1
insert into @t select strNum1,strNum2,@i,right('0'+strNum2,3) from AAA where strNum1 = @strNum1

while @@rowcount <>0
begin
set @i=@i+1
insert into @t
select
a.strNum1,a.strNum2,@i,b.Ord+a.strNum2
from
AAA a,@t b
where
a.strNum1=b.strNum2 and b.Level=@i-1
and
not exists(select 1 from @t where strNum1=a.strNum1 and strNum2=a.strNum2)
end

select * from @t order by Ord
end
go
:
beyondamane 2008-04-14
  • 打赏
  • 举报
回复
直接在sql语句里面这么写就可以调用了:select * from dbo.f_getChild('01') order by Ord
zl_c 2008-04-14
  • 打赏
  • 举报
回复
其实你这个功能可以直接用存储过程就可以实现,ASP调用存储过程,取得记录集就可以.
mzcih 2008-04-14
  • 打赏
  • 举报
回复
那可以将以上函数写成ASP的吗?

或者正接改成ASP的SQL语句?
zl_c 2008-04-14
  • 打赏
  • 举报
回复
这个还真有点麻烦,再写一个存储过程,把'01'这个值传进去来处理吧.

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧