实验14 存储过程与函数 下载本文

内容发布更新时间 : 2024/5/28 5:54:57星期一 下面是文章的全部内容请认真阅读。

(select * from CP where 产品名称=@cp_name)

请给出执行测试结果:查询产品名称为“mp3”的产品情况

2.按某年某季度统计给定产品名称的销售数量及销售金额。(函数名为:FU1_CPXS) 请给出程序源码:

create function FU1_CPXS (@cp_name char(20),@year int,@quarter int)

returns table as return

(select sum(数量) as 销售数量, sum(销售额) as 销售总额 from cp,xss,cpxsb

where cp.产品编号=cpxsb.产品编号 and xss.客户编号=cpxsb.客户编号 and datepart(year,销售日期)=@year and datepart(quarter,销售日期)=@quarter and 产品名称=@cp_name group by 产品名称)

请给出执行测试结果:查询2004年第3季度彩色电视机的销售数量和销售金额

(数据库中无第三季度的数据,改为查询第一

季度)

3.根据销售商名称,统计其在某年某季度内销售商品名称、数量及金额。(函数名为FU2_CPXS)

请给出程序源码:

Create function FU2_CPXS (@kh_name char(20),@year int,@quarter int)

第 16 页 共 17 页

returns table as return

(select 产品名称,sum(数量) as 销售数量, sum(销售额) as 销售总额 from cp,xss,cpxsb

where cp.产品编号=cpxsb.产品编号 and xss.客户编号=cpxsb.客户编号 and datepart(year,销售日期)=@year and datepart(quarter,销售日期)=@quarter and 客户名称=@kh_name group by 产品名称)

请给出执行测试结果:查询广电公司2004年第1季度销售的产品名称、销售数量和销售金额。

第 17 页 共 17 页