zoukankan      html  css  js  c++  java
  • SQL 常用

    去空格 replace(ltrim(rtrim(phone)),' ','')
    字符串轉化成整數 select MAX(convert(bigint,(replace(ltrim(rtrim([EmployeeNo])),' ',''))))
    --sql Function 函數:
    create function fn_IsWorkDay(@date datetime)
    returns bit
    as
    BEGIN
    declare @IsWorkDay bit
    declare @WeekDayNum int
    declare @Type varchar(10) --存放某一天是ON 還是OFF
    set @IsWorkDay=0      --工作日,默認為False
    set @date=CONVERT(varchar(12) , @date, 23 ) --'yyyy-MM-dd'
    set @WeekDayNum=(select datepart(weekday,@date))
    select @Type=(select [Type] from [HolidayDate] where CONVERT(varchar(10),[Date],120)=@date) --ON OFF
     if(@WeekDayNum in (7,1)) --周末
      begin
       if(@Type='ON')
       begin
        set @IsWorkDay=1
       end
      end
     else if(@WeekDayNum not in (7,1)) --周一到周五
      begin
       if(@Type='OFF')
       begin
        set @IsWorkDay=0
       end
      end
    return @IsWorkDay
    END

    --定義遊標實現數據更新
    declare @EmpNo varchar(10)
    declare @DptCodeB varchar(12)
    declare @DptCodeA varchar(12)
    declare cur cursor
    for select [EmployeeNo],[DepartCodeB] from [MainEmployee] where [DepartCodeB]<>'' and [DepartCodeB] is not null
    open cur
    fetch next from cur into @EmpNo,@DptCodeB
    while(@@fetch_status=0)
     begin
      select @DptCodeA=(select [DepartCodeA] from [Plant_Dept] where [DepartCodeB]=@DptCodeB) --Select DeptCodeA
      update [MainEmployee] set [DepartCodeA]=@DptCodeA where [EmployeeNo]=@EmpNo
      fetch next from cur into @EmpNo,@DptCodeB
     end
    close cur
    deallocate cur
  • 相关阅读:
    【todo】深入理解设计模式
    一个最简单的LRUCache实现 (JAVA)
    Redis之AOF重写及其实现原理
    【todo】nosql 的几种类型研究
    【todo】redis 中的hyperloglog原理
    【todo】ER分片
    【todo】研究一下mycat的原理
    【todo】研究一下sharding-jdbc的原理
    为什么存储过程比sql语句效率高?
    存储过程这一篇就够了
  • 原文地址:https://www.cnblogs.com/siri/p/2920540.html
Copyright © 2011-2022 走看看