zoukankan      html  css  js  c++  java
  • 【Vegas原创】按自定义格式进行编号的SQL自定义函数

    生成格式如:DT.EMP.0000000001的自增emp_id, 加入EmpBaseINfo表中。

    --生成格式如DT.EMP.0000000001  【Vegas Add】
    ALTER FUNCTION [dbo].[Get_EmpBaseInfo_AccountID](@RowID as int)
    RETURNS nvarchar(50as 
    begin

        
    declare @oid nvarchar(50)
        
    declare @headStr nvarchar(50)

        
    set @headStr='DT.EMP.'    

    ----------------------------RowID的计算--------------------------------------
        if exists(select 1 from empbaseinfo)
            
    --如empbaseinfo存在数据,count(*)后直接加RowID
            begin
                
    select  @oid=count(1from empbaseinfo  
                
    set @oid=@oid+ @RowID 
            
    end
        
    else 
            
    set @oid=@RowID
           
    ----------------------------补全十个数------------------------------
        declare @str nvarchar(50--临时编号

        
    set @str=convert(nvarchar,(convert(int,right(@oid,10))))  

        
    while (10-len(@str)>0)
            
    begin
                 
    set @str='0'+@str    
            
    end

        
    set @oid=@headStr+@str

    ---------------------------返回值---------------------------------------------------------
    RETURN @oid
    end     

     调用:

    select dbo.Get_EmpBaseInfo_AccountID(ROW_NUMBER() OVER(ORDER BY hbdwno)) as id,
            hbdwno,hbdbno,hbdenm,hbdcnm,
            (
    case hbdgdr when 1 then 'M' when 0 then 'F' end),
            (
    case hbdidl when 1 then 'IDL' when 0 then 'DL' end),
            hbdwdt,hbdbir,hbdmds,
    'DT' as domain
    from hrmsdt.hrms.dbo.hrshhbd
    order by hbdwno

      

    参考文档:http://www.cnblogs.com/ringwang/archive/2008/05/14/1197065.html

  • 相关阅读:
    Android UI开发 popupwindow介绍以及代码实例
    前端之Android入门(5) – MVC模式(下)
    前端之Android入门(4) – MVC模式(中)
    前端之Android入门(3) – MVC模式(上)
    前端之Android入门(2) – 程序目录及UI简介
    前端之Android入门(1) – 环境配置
    android之SQLite数据库应用(二)
    android之SQLite数据库应用(一)
    android 裁剪图片大小 控制图片尺寸
    Android应用盈利广告平台的嵌入方法详解
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/3744403.html
Copyright © 2011-2022 走看看