转至繁体中文版     | 网站首页 | 文章中心 | 下载中心 | 图片中心 | 笑话频道 | 教程频道 | 会员中心 | 雁过留声 | 
最新公告:     "MinTao学以致用网"欢迎您的光临,你的支持便是我们的动力,欢迎广大网友和各界人士亲临指导,你们的一个小小的建议便是我们发展的开路石!  [MinTao  2007年9月5日]        
您现在的位置: MinTao学以致用网 >> 文章中心 >> 电子课堂 >> 数据库 >> Sql Server >> 文章正文
专题栏目
更多内容
最新推荐 更多内容
相关文章
SQL语言快速入门之一
SQL语言快速入门之二
SQL语言快速入门之三(一
SQL7.0储存过程调试
通过HTTP访问SQL Server
SQL Server的存储过程调
SQL Server安全性简介
定制PB与SQL Anywhere的
全面接触SQL语法
SQL 语法参考手册
更多内容
本人的原创代码(SQL及T_SQL)         
本人的原创代码(SQL及T_SQL)
作者:cyz1980 文章来源:不详 点击数: 更新时间:2007-11-14 12:59:57
_Customers.CustomerID
--------------------------------------------------------------------------------
/*显示人员消费情况及联系SQL代码*/
SELECT dbo.T_Customers.Name AS 姓名, dbo.T_ConsumeRec.OpDt AS 消费时间,
      dbo.T_ConsumeRec.OpFare AS 消费额, dbo.T_ConsumeRec.OddFare AS 余额,
      ISNULL(dbo.T_Department.DpName1, '''''''') + ISNULL(dbo.T_Department.DpName2, '''''''')
      + ISNULL(dbo.T_Department.DpName3, '''''''') AS 部门,
      dbo.T_Station.StatName AS 工作站, dbo.T_Eatery.STName AS 食堂,
      dbo.T_Group.GrpName AS 食堂组, dbo.T_Terms.Port AS 端口号,
      dbo.T_Terms.TermName AS 窗机名称
FROM dbo.T_ConsumeRec INNER JOIN
      dbo.T_Customers INNER JOIN
      dbo.T_Department ON SUBSTRING(dbo.T_Customers.Account, 1, 2)
      = dbo.T_Department.DpCode1 AND SUBSTRING(dbo.T_Customers.Account, 3, 2)
      = dbo.T_Department.DpCode2 AND SUBSTRING(dbo.T_Customers.Account, 5, 3)
      = dbo.T_Department.DpCode3 ON
      dbo.T_ConsumeRec.CustomerID = dbo.T_Customers.CustomerID INNER JOIN
      dbo.T_Eatery ON dbo.T_ConsumeRec.StatID = dbo.T_Eatery.StatID INNER JOIN
      dbo.T_Group ON dbo.T_ConsumeRec.StatID = dbo.T_Group.StatID AND
      dbo.T_Eatery.STID = dbo.T_Group.STID INNER JOIN
      dbo.T_Station ON dbo.T_ConsumeRec.StatID = dbo.T_Station.StatID INNER JOIN
      dbo.T_Terms ON dbo.T_Eatery.StatID = dbo.T_Terms.StatID AND
      dbo.T_Eatery.STID = dbo.T_Terms.STID AND
      dbo.T_Group.GrpID = dbo.T_Terms.GrpID AND
      dbo.T_ConsumeRec.Port = dbo.T_Terms.Port AND
      dbo.T_ConsumeRec.Term = dbo.T_Terms.Term
----------------------------------------------------------------------------------------
/*列出存取款及联系SQL代码*/
SELECT dbo.T_Customers.Name AS 姓名, ISNULL(dbo.T_Department.DpName1, '''''''') + ISNULL(dbo.T_Department.DpName2, '''''''')
      + ISNULL(dbo.T_Department.DpName3, '''''''') AS 部门,
      dbo.T_CashRec.CashDt AS 存取款时间, dbo.T_CashRec.InFare AS 存款额,
      dbo.T_CashRec.OutFare AS 取款额, dbo.T_CashRec.OddFare AS 余额,
      dbo.T_Station.StatName AS 工作站, dbo.T_Cashiers.Name AS 出纳员,
      dbo.T_CashRec.Port AS 出纳机端口, dbo.T_CashRec.Term AS 出纳机机器号
FROM dbo.T_Station INNER JOIN
      dbo.T_Cashiers ON dbo.T_Station.StatID = dbo.T_Cashiers.StatID INNER JOIN
      dbo.T_Customers INNER JOIN
      dbo.T_Department ON SUBSTRING(dbo.T_Customers.Account, 1, 2)
      = dbo.T_Department.DpCode1 AND SUBSTRING(dbo.T_Customers.Account, 3, 2)
      = dbo.T_Department.DpCode2 AND SUBSTRING(dbo.T_Customers.Account, 5, 3)
      = dbo.T_Department.DpCode3 INNER JOIN
      dbo.T_CashRec ON dbo.T_Customers.CustomerID = dbo.T_CashRec.CustomerID ON
      dbo.T_Cashiers.CashID = dbo.T_CashRec.CashID AND
      dbo.T_Station.StatID = dbo.T_CashRec.StatID
-----------------------------------------------------------------------------------------
/*列出incomerec帐本中与现有窗机比较后不存在的窗机*/
SELECT Port, Term
FROM T_IncomeRec
WHERE (Term <> ALL
          (SELECT term
         FROM t_terms
         WHERE statid = 2)) AND (StatID = 2)
----------------------------------------------------------------------------------------
/*公安专发放补助前处理的SQL代码(当月补助形成后)*/
if exists(select customerid from t_subsidynotputout where (cardtype=5 or cardtype=6) and subsidy=0 group by customerid having count(*)>1)
  begin /*判断5、6类卡是否存在一人两条前期记录即存在去年没领补助的教师*/
    select month ,customerid as 去年没领补助的教师的客户号,cardtype,subsidy from t_subsidynotputout where     customerid
    =any(select customerid from t_subsidynotputout where (cardtype=5 or cardtype=6) and subsidy=0 group by     customerid having count(*)>1)
  end
else
 begin
--go
  insert into t_subsidymonthplan(month,customerid,cardtype,subsidy)
  select * from t_subsidynotputout where (cardtype=5 or cardtype=6) and subsidy=0
/*公安专在当月补助形成后(5、6类卡为教师卡,一年只领一次补助),发补助前:向表monthplan插入符合在表notputout中5、6类卡subsidy为0的记录,
注意是否存在一人两条前期记录(一般不会出现这种况,除非去年没领补助),否则在monthplan表中后面的更新时间会出错!!*/
--go
  delete t_subsidynotputout where (cardtype=5 or cardtype=6) and subsidy=0
/*删除notputout被复制的记录*/
--go
  update t_subsidymonthplan set month=''''2004-12-1'''' where (cardtype=5 or cardtype=6) and subsidy=0
/*更改表monthplan中的month日期,月份根据实际定*/
--go
  update t_customers set subsidydt=''''2004-12-1'''' where (cardtype=5 or cardtype=6) and cursubsidyfare>0
/*更改t_customers表中的补助时间,注意与t_subsidymonthplan表中的month日期值保持一致!!*/
 end
  go
  select sum(cursubsidyfare) as 客户帐本的补助总额 from t_customers
  go
  select sum(subsidy) as 前期补助总额 from t_subsidynotputout
  go
 select sum(subsidy) as 当月补助总额 from t_subsidymonthplan
/*查询客户帐本的补助总额是否等于前期补助总额与当月补助总额之和!*/
--------------------------------------------------------------------------------------------------
                 /*师大补助月报表信息纠正T_SQL代码*/
declare @k int, @k1 int,@k2 int,@month datetime,@subsidyFare money,@cardtype tinyint,@subsidyFare1 money,@subsidyFare2 money

   /*清除冲突补助月份的T_SQL代码开始*/
declare @id int
while 1=1
begin
         SELECT @id=T_SubsidyNotPutOut.CustomerID ,@month=dbo.T_SubsidyNotPutOut.[Month]
         FROM dbo.T_SubsidyNotPutOut INNER JOIN
               dbo.T_SubsidyPutOut ON
               dbo.T_SubsidyNotPutOut.CustomerID = dbo.T_SubsidyPutOut.CustomerID AND
                dbo.T_SubsidyNotPutOut.[Month] = dbo.T_SubsidyPutOut.[Month]
if (exists(select * FROM T_SubsidyNotPutOut
    WHERE (CustomerID=@id and [Month] = @month)))
begin
   DELETE FROM T_SubsidyNotPutOut
   WHERE (CustomerID=@id and [Month] = @month)   
end
else
  begin
    print ''''没有相关客户的相关补助发放冲突月份!或补助冲突月份已经清理完毕!''''
    break
  end
end   /**/
while 1=1
begin
         SELECT @id=T_Subsidymonthplan.CustomerID ,@month=dbo.T_Subsidymonthplan.[Month]
         FROM dbo.T_Subsidymonthplan INNER JOIN
               dbo.T_SubsidyPutOut ON
               dbo.T_Subsidymonthplan.CustomerID = dbo.T_Su

上一页  [1] [2] [3] [4] 下一页

文章录入:mintao    责任编辑:mintao 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007 MinTao学以致用网(www.mintao.net) Inc All Rights Reserved.
    QQ:543098146有事请Q我! QQ:261561092有事请Q我 QQ:179647303有事请Q我 MSN:min906@126.com
    站长:MinTao 信息产业部ICP备案号:鄂ICP备07500065号

    学以致用是我们学习者的至高境界和不懈追求,[MinTao学以致用网]与大家共同学习,共同进步……
    信息产业部备案
    *鄂ICP备07500065号