zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Mac_Homebrew
    Python的路径引用
    OpenTSDB-Writing Data
    OpenTSDB介绍
    Git文件状态描述
    TCollector
    TEXT和BLOB区别
    MySQL索引与Index Condition Pushdown
    webService入门学习(一)
    redis学习笔记(一 基本操作)。
  • 原文地址:https://www.cnblogs.com/gxmaspx/p/2608291.html
Copyright © 2011-2022 走看看