用sql server存储过程写一个报表,麻烦大神帮帮忙写个能用的,C币好说(实习任务!)

这是报表内容

这是我写的,新手见谅
图片说明
图片说明
图片说明

这是运行结果

这是一些参数

2个回答

select ISNULL(T1.月份,T2.月份) as 月份,
装配总数,合同金额,装配成本,装配利润,装配利润率,
销售台数,开票金额,销售成本,销售利润,销售利润率
FROM
(
select cast(YEAR(EXTEND50) as nvarchar(4)) + '-' + cast(MONTH(EXTEND50) as nvarchar(2)) as 月份,
COUNT(sub_account_id) as 装配总数,
SUM(discount_money) as 合同金额 ,
SUM(EXTEND36) as 装配成本 ,
SUM(discount_money) / 1.17 - SUM(EXTEND36) as 装配利润 ,
(SUM(discount_money) / 1.17 - SUM(EXTEND36) ) / SUM(discount_money) as 装配利润率
from T_CONTRACT_ORDER
WHERE EXTEND1 = '装配工程单' AND EXTEND50 >= @KSRQ AND EXTEND50 <= @JSRQ
Group By cast(YEAR(EXTEND50) as nvarchar(4)) + '-' + cast(MONTH(EXTEND50) as nvarchar(2))
) T1
FULL OUTER JOIN
(
Select cast(YEAR(O.EXTEND50) as nvarchar(4)) + '-' + cast(MONTH(O.EXTEND50) as nvarchar(2)) as 月份,
SUM(D.INVOICED_NUM) as 销售台数,
SUM(O.INVOICED_MONEY) as 开票金额 ,
SUM(O.EXTEND36) as 销售成本 ,
SUM(O.INVOICED_MONEY) / 1.17 - SUM(O.EXTEND36) as 销售利润 ,
(SUM(O.INVOICED_MONEY) / 1.17 - SUM(O.EXTEND36) ) / SUM(O.INVOICED_MONEY) as 销售利润率
FROM T_CONTRACT_ORDER O INNER JOIN T_CONTRACT_ORDER_detail D ON O.sub_account_id = D.sub_account_id
where O.EXTEND50 >= @KSRQ AND O.EXTEND50 <= @JSRQ and O.EXTEND1 = '工程销售'
GROUP BY cast(YEAR(O.EXTEND50) as nvarchar(4)) + '-' + cast(MONTH(O.EXTEND50) as nvarchar(2))
) T2
ON T1.月份 = T2.月份

Create procedure procedue_name

[@parameter data_type][output]

[with]{recompile|encryption}

as

sql_statement

解释:

output:表示此参数是可传回的

with {recompile|encryption}

recompile:表示每次执行此存储过程时都重新编译一次

encryption:所创建的存储过程的内容会被加密

如:

表book的内容如下

编号 书名 价格

001 C语言入门 $30

002 PowerBuilder报表开发 $52

实例1:查询表Book的内容的存储过程

create proc query_book

as

select * from book

go

exec query_book

实例2:加入一笔记录到表book,并查询此表中所有书籍的总金额

Create proc insert_book

@param1 char(10),@param2 varchar(20),@param3 money,@param4 money output

with encryption ---------加密

as

insert book(编号,书名,价格) Values(@param1,@param2,@param3)

select @param4=sum(价格) from book

go

执行例子:

declare @total_price money

exec insert_book '003','Delphi 控件开发指南',$100,@total_price

print '总金额为'+convert(varchar,@total_price)

go

存储过程的3种传回值:

1.以Return传回整数

2.以output格式传回参数

3.Recordset

传回值的区别:

output和return都可在批次程式中用变量接收,而recordset则传回到执行批次的客户端中

实例3:设有两个表为Product,Order,其表内容如下:

Product

qq_39372401
qq_39372401 哥,你能不说我的具体点,就说我写的这咋改,或者您给写一个都成,我就一新手,您整这我也不会啊
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!