转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> Sql Server >> 正文
本人的原创代码(SQL及T_SQL)         

本人的原创代码(SQL及T_SQL)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3720 更新时间:2007/11/14 12:59:57
p;     COUNT(*) AS CountOpfare
                 FROM (SELECT StatID, Port, Term, CustomerID,
                               RTRIM(CAST(YEAR(dbo.T_ConsumeRec.OpDt) AS char))
                               + ''''-'''' + RTRIM(CAST(MONTH(dbo.T_ConsumeRec.OpDt)
                               AS char)) + ''''-'''' + RTRIM(CAST(DAY(dbo.T_ConsumeRec.OpDt)
                               AS char)) AS dt, CollectDt, MealID, OpFare, MngFare,
                               OddFare
                         FROM dbo.T_ConsumeRec) AS consumerec INNER JOIN
                       dbo.T_Customers ON
                       ConsumeRec.CustomerID = dbo.T_Customers.CustomerID
                 WHERE (dbo.T_Customers.CardType = 1)
                 GROUP BY ConsumeRec.StatID, ConsumeRec.Port, ConsumeRec.Term,
                       ConsumeRec.MealID, ConsumeRec.dt) s_c_opf ON
              s_c_opf.StatID = dbo.T_IncomeRec.StatID AND
              s_c_opf.Port = dbo.T_IncomeRec.Port AND
              s_c_opf.Term = dbo.T_IncomeRec.Term AND
              s_c_opf.MealID = dbo.T_IncomeRec.MealID AND
              dbo.T_IncomeRec.SumDt = s_c_opf.dt
        WHERE (dbo.T_IncomeRec.SumDt BETWEEN ''''2004-7-6'''' AND ''''2004-7-6''''))
      yf INNER JOIN
      dbo.T_Eatery ON yf.StatID = dbo.T_Eatery.StatID INNER JOIN
      dbo.T_Group ON yf.StatID = dbo.T_Group.StatID AND
      dbo.T_Eatery.STID = dbo.T_Group.STID INNER JOIN
      dbo.T_Station ON yf.StatID = dbo.T_Station.StatID INNER JOIN
      dbo.T_Terms ON dbo.T_Eatery.StatID = dbo.T_Terms.StatID AND
      dbo.T_Group.STID = dbo.T_Terms.STID AND
      dbo.T_Group.GrpID = dbo.T_Terms.GrpID AND yf.Port = dbo.T_Terms.Port AND
      yf.Term = dbo.T_Terms.Term INNER JOIN
      dbo.T_Meal ON yf.MealID = dbo.T_Meal.MealID

-------------------------------------------------------------------------------------

/*列出未注册卡SQL代码*/
select t_consumerec.customerid as 未注册客户号,t_consumerec.oddfare as 未注册卡余额,t_consumerec.opdt as 未注册卡消费时间 from t_consumerec where t_consumerec.customerid<>all(select customerid from t_customers)
and t_consumerec.opdt between ''''2004-9-12 00:00:00'''' and ''''2004-9-15 23:59:59''''
-----------------------------------------------------------------------
/*门禁系统后台数据库IDCARD中T_customers表的触发器*/
create trigger delterms on t_customers for update as
declare @id int,@k1 int,@k2 int
select @k1=count(*) from  t_customers where Inserted
select @k2=count(*) from  t_customers where Deleted
if @k1=@k2 and @k1>0
begin
 select  @id=t_customers.customerid from t_customers,t_terms where t_customers.customerid=t_terms.customerid and
         t_customers.cardno<>t_terms.cardno
         delete from t_terms where customerid=@id
end
-----------------------------------------------------------------------
/*门禁系统的卡号纠正T_SQL代码*/
declare @id int, @no int
while 1=1
begin
   select @id=t_customers.customerid,@no=t_customers.cardno  from t_customers,t_terms where      

t_customers.customerid=t_terms.customerid and t_customers.cardno<>t_terms.cardno  
   order by t_customers.customerid asc

   if exists(select t_customers.customerid from t_customers,t_terms  where t_customers.customerid=t_terms.customerid and    t_customers.cardno<>t_terms.cardno )
    begin
       update t_terms set cardno=@no where customerid=@id
    end
   else
    begin
      print ''''更新完毕!''''
      break
    end    
end
-----------------------------------------------------------------------
/*清除冲突补助月份的T_SQL代码*/
declare @id int
declare @month datetime
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)
   continue
end
else
  begin
    print ''''没有相关客户的相关补助发放冲突月份!或补助冲突月份已经清理完毕!''''
    break
  end
end
-----------------------------------------------------------------------
/*前期补助无法发放名单SQL代码*/
SELECT dbo.T_Customers.Name AS 姓名, dbo.T_SubsidyNotPutOut.[Month] AS 月份
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] INNER JOIN
      dbo.T_Customers ON
      dbo.T_SubsidyNotPutOut.CustomerID = dbo.T

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


[办公软件]在sybase中插入图片、PDF、文本文件  [办公软件]安装Sybase ASE
[办公软件]linux指令大全(完整篇)  [办公软件]Linux新手入门常用命令大全
[办公软件]在RedHat Linux 9里安装gaim0.80  [办公软件]浅谈Linux 下Java 1.5 汉字方块问题解决方法
[办公软件]Linux程序员必读:中文化与GB18030标准  [办公软件]linux指令大全
[办公软件]制作Linux启动盘的四种方法  [办公软件]Linux文件系统的反删除方法
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

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

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

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

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台