• SQL 日期转换及复制表


    1、日期函数dateadd进行加减年月日小时,拼接标准日期格式

    1
    set fldDate=Convert(date,dateadd(hour,-1,Convert(datetime,fldDate + ' ' +CONVERT(varchar(2),fldTime)+':00:00'))),fldTime=DATEPART(HOUR,dateadd(hour,-1,Convert(datetime,fldDate + ' ' +CONVERT(varchar(2),fldTime)+':00:00')))

    2、len函数判断字符串长度有case  when then else end 进行填补日期类型

    2case  When len(fldMonth)=1 then '0'+convert(varchar(2),fldMonth) else convert(varchar(2),fldMonth) end

     3、根据一张表的内容复制到另一张表要写出所对应的字段重要,几个日期函数顺便提一下

    3insert into tblEQIA_RPI_Basedata (fldSTCode,fldPCode,fldSYear,fldSMonth,fldSDay,fldSHour,fldSMinute,fldEYear,fldEMonth,fldEDay,fldEHour,fldEMinute ,fldItemCode ,fldItemValue ,fldSource,fldUserID)
       select '210200',fldPCode,YEAR(F2),MONTH(F2),DAY(F2),0,0,YEAR(F2),MONTH(F2),DAY(F2),23,59,fldItemCode,F3,0,0 from dbo.Sheet1$
       inner join tblEQIA_R_Point on F1=fldSort 
       inner join tblEQIA_R_Item on F4=fldItemName 
      where tblEQIA_R_Point.fldYear =2011

     

     4、删除表进行条件判断是否存在

    1 4delete   tblEQIP_S_CompanyInfo from tblEQIP_S_CompanyInfo T where   
    2 exists(   
    3 select 1  from  tblEQIP_S_CompanyInfo   where   fldMonitorYear=T.fldMonitorYear   and   fldDistrictCode=T.fldDistrictCode and  fldCompanyName=T.fldCompanyName 
    4 and  fldAutoID < T.fldAutoID
    5 )
    生活因为改变而美丽.让我每天改变一点点.努力多一点点.成功就多两大点.这就是1+1>2
  • 相关阅读:
    inndo 表与存储逻辑_1
    msyql master thread
    redo log重做日志缓冲
    redo log 重做日志
    Latex 写算法伪代码
    Just for test
    ASP.NET Web API 2 OData v4教程
    MVC系统过滤器 OutputCacheAttribute
    MVC系统过滤器、自定义过滤器
    .NET如何从配置文件中获取连接字符串
  • 原文地址:https://www.cnblogs.com/gxmaspx/p/2608291.html
Copyright © 2020-2023  润新知