转至繁体中文版     | 网站首页 | 文章中心 | 下载中心 | 图片中心 | 笑话频道 | 教程频道 | 会员中心 | 雁过留声 | 
最新公告:     "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
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] 下一页

文章录入: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号