易截截图软件、单文件、免安装、纯绿色、仅160KB

花了半天写出来的个sql语句,分享下

Declare @T Table(
    CFF_Loanno   nvarchar(100),
    BANK_Name_2  nvarchar(100),
    CFF_code  nvarchar(100),
    CFF_date   datetime,
    CFF_amt  decimal(18, 6),
    CFF_repay_date  datetime,
    COMP_Name_2   nvarchar(100)
)
---临时表,存放基础数据
insert into @T(CFF_Loanno ,
    BANK_Name_2  ,
    CFF_code,
    CFF_date,
    CFF_amt,
    CFF_repay_date,
    COMP_Name_2)
SELECT A.CFF_Loanno,B.BANK_Name_2,A.CFF_code,A.CFF_date,A.CFF_amt,A.CFF_repay_date,C.COMP_Name_2
from cashflow_financing as A
inner join Bank as B on
A.CFF_Bank = B.BANK_Code
inner join Company as C on
A.CFF_repay_company =  C.COMP_Code
---小计表,按照还款日期汇总
select  N'B' as ord,N'小计' as class,
CFF_Loanno as CFF_Loanno ,
CONVERT(varchar(100), CFF_repay_date, 23) as BANK_Name_2  ,
     NULL as CFF_code,
     NULL as CFF_date,
    isnull((select sum(CFF_amt) from @T as a where a.CFF_Loanno = b.CFF_Loanno and a.CFF_repay_date = b.CFF_repay_date), 0) as CFF_amt,
     NULL as CFF_repay_date,
     NULL as COMP_Name_2
 from @T as b group by CFF_Loanno, CFF_repay_date
union all
---明细表
select N'A' as ord,N'明细' as class,c.*
from @T as c
union all
---合计表
select  N'C' as ord,N'合计' as class,
CFF_Loanno as CFF_Loanno ,
     NULL as BANK_Name_2  ,
     NULL as CFF_code,
     NULL as CFF_date,
    isnull((select sum(CFF_amt) from @T as d where d.CFF_Loanno = e.CFF_Loanno), 0) as CFF_amt,
     NULL as CFF_repay_date,
     NULL as COMP_Name_2
 from @T as e


相关文档:

SQL数据中运行cmd命令

在sql查询分析器里面是不能直接运行cmd命令的
但是SQL给出了一个接口
--打开高级设置
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
--打开xp_cmdshell扩展存储过程
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
首先 打开一些配置
然后执行你要运行cmd命令
exec master..xp_cmdshell 'net star ......

【转】Oracle SQL性能优化技巧大总结

(1) 选择最有效率的表名顺序(只在基于规则的优化
器中有效):
   
Oracle

解析器按照从右到左的顺序处理from子句中的表名,from子句中写在最后的表(基础表 driving
table)将被最先处理,在from子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表。假如有3个以上的表连接查询,
那就 ......

SQL Server如何跨实例访问数据库

在我们日常使用SQL Server数据库时,经常遇到需要在实例Instance01中跨实例访问Instance02中的数据。例如在做数据迁移时,如下语句:
insert into Instance01.DB01.dbo.Table01
          select * from Instance02.DB01.dbo.Table01
普通情况下,这样做是不允许的,因为SQ ......

SQL Lite

SQL Lite
SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine.
It is a open source product and can be downloaded from http://www.sqlite.org/ . SQL Lite is best suited in Smart Client architecture, where we can locally store all ......

本人写的第一个PL/SQL过程

看到别人在论坛的提问:
一个表的效率问题
今天碰到2张表
1张 有字段
表A有
jtbh(家庭编号) hzxm(户主姓名) hnbh(户内最大编号) 
1000          张三            03
1001          赵六..........................
表 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号