函数

--标量函数
--
创建函数
create function Fun_Cost
(@x int,@y money)
returns money
as
begin
return (@x*@y)
end
--使用函数
alter table goods add 金额 as dbo.Fun_cost(数量,进货价)
go
--验证函数
select * from Goods
go
--表值函数
--
1\内嵌表值函数
create function Fun_Total
(@bt datetime,@ef datetime)
returns table
as
return
(select goods.商品名称,sell.数量 from goods,sell where sell.售出时间 between @bt and @ef and Goods.商品编号=sell.商品编号)
select * from dbo.Fun_Total('2005-1-1','2005-1-31')
go
--2\多语句表值函数
create function Fun_Lan
(@price money)
returns @Fun_Lan table
(
商品编号 int primary key not null,
商品名称 varchar(20) not null,
生产厂商 varchar(30) not null,
进货价 money not null,
进货时间 datetime not null
)
as
begin
insert @Fun_Lan
select 商品编号,商品名称,生产厂商,进货价,进货时间 from goods
where (进货价>@price)
return
end
select * from dbo.Fun_Lan(1000)
go
---


转载于:https://www.cnblogs.com/school/archive/2011/11/02/2233511.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值