sql 用户自定义函数 15
SETQUOTED_IDENTIFIEROFFGOSETANSI_NULLSOFFGOCREATEFUNCTIONF_BOM(@MD003VARCHAR(20),@MD0...
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE
FUNCTION F_BOM(@MD003 VARCHAR(20),@MD006 INT)
returns
@t table(MD003 VARCHAR(20),MD006 INT)
as
begin
insert into @t(MD003,MD006) select MD003,MD006*@MD006
FROM BOMMD
WHERE MD001=@MD003 AND MD014='Y'
while @@rowcount<>0
begin
insert into @t(MD003,MD006)
select
A.MD003,A.MD006*B.MD006
from
BOMMD A,@t B
where
A.MD014='Y' AND
A.MD001=B.MD003 collate Chinese_PRC_CI_AI_WS
and
not exists(select 1 from @t where MD003=A.MD003 collate Chinese_PRC_CI_AI_WS)
end
return
end
谁能帮我解释下这段代码啊?
要具体点的啊~!
@t是不是不真正存在的表啊?? 展开
GO
SET ANSI_NULLS OFF
GO
CREATE
FUNCTION F_BOM(@MD003 VARCHAR(20),@MD006 INT)
returns
@t table(MD003 VARCHAR(20),MD006 INT)
as
begin
insert into @t(MD003,MD006) select MD003,MD006*@MD006
FROM BOMMD
WHERE MD001=@MD003 AND MD014='Y'
while @@rowcount<>0
begin
insert into @t(MD003,MD006)
select
A.MD003,A.MD006*B.MD006
from
BOMMD A,@t B
where
A.MD014='Y' AND
A.MD001=B.MD003 collate Chinese_PRC_CI_AI_WS
and
not exists(select 1 from @t where MD003=A.MD003 collate Chinese_PRC_CI_AI_WS)
end
return
end
谁能帮我解释下这段代码啊?
要具体点的啊~!
@t是不是不真正存在的表啊?? 展开
2个回答
展开全部
CREATE
FUNCTION F_BOM(@MD003 VARCHAR(20),@MD006 INT) --创建一个函数
returns
@t table(MD003 VARCHAR(20),MD006 INT) ---返回一个表,字段是自己定义的
begin
insert into @t(MD003,MD006) select MD003,MD006*@MD006 FROM BOMMD WHERE MD001=@MD003 AND MD014='Y' -----开始函数,向自己定义的表中插入数据
while @@rowcount<>0 ----如果上个语句插入了,开始下面的
insert into @t(MD003,MD006)
select
A.MD003,A.MD006*B.MD006
from
BOMMD A,@t B
where
A.MD014='Y' AND
A.MD001=B.MD003 collate Chinese_PRC_CI_AI_WS
and
not exists(select 1 from @t where MD003=A.MD003 collate Chinese_PRC_CI_AI_WS)
----根据where条件再次插入数据
FUNCTION F_BOM(@MD003 VARCHAR(20),@MD006 INT) --创建一个函数
returns
@t table(MD003 VARCHAR(20),MD006 INT) ---返回一个表,字段是自己定义的
begin
insert into @t(MD003,MD006) select MD003,MD006*@MD006 FROM BOMMD WHERE MD001=@MD003 AND MD014='Y' -----开始函数,向自己定义的表中插入数据
while @@rowcount<>0 ----如果上个语句插入了,开始下面的
insert into @t(MD003,MD006)
select
A.MD003,A.MD006*B.MD006
from
BOMMD A,@t B
where
A.MD014='Y' AND
A.MD001=B.MD003 collate Chinese_PRC_CI_AI_WS
and
not exists(select 1 from @t where MD003=A.MD003 collate Chinese_PRC_CI_AI_WS)
----根据where条件再次插入数据
展开全部
查看BOM的物料的结构
计算BOM参照
计算BOM参照
参考资料: http://blog.csdn.net/roy_88/archive/2006/12/24/1458449.aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询