易截截图软件、单文件、免安装、纯绿色、仅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 ......

windows验证方式连接SQL 数据库

C#中以windows验证方式连接SQL server数据库的类。很多人连接数据库时可能都是网上查了然后就连了,对于参数的含义倒是没怎么在意,偶也是(呵呵),当然我们都注重结果嘛,可是这样不容易记忆每次连的时候都是上网查,感觉挺不方便,所以索性查了一下。~~~Integrated Security=True;表示在连接数据库进行身份验证时用wind ......

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

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

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

oracle sql 求种菜时间

-- create by zh
-- n 是作物的时间,x 是希望在几点成熟,返回播种的时间
with t as
(
select 64 n,9 x from dual union all
select 64 n,13 x from dual union all
select 64 n,17 x from dual union all
select 64 n,20 x from dual
)
select '成熟时间:'     || lpad(to_char(n),4,' ' ......

在SQL中向多个数据库中插入相同的记录

今天一个朋友问到这个问题,其实很好解决:
declare   @dbname   varchar(50)  
  declare   c_database   cursor   for  
      select   name   from   master.dbo.sysdatabas ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号