zoukankan      html  css  js  c++  java
  • SqlServer Function

    set quoted_identifier on;
    set ansi_nulls on;
    go
    
    create function [dbo].[Get_StrArrayStrOfIndex]
           ( @str NVarchar(max) ,  --要分割的字符串
             @split NVarchar(10) ,  --分隔符号
             @index Int --取第几个元素
             )
    returns NVarchar(max)
    as
    begin
        declare @location Int;
        declare @start Int;
        declare @next Int;
        declare @seed Int;
    
        set @str = LTrim(RTrim(@str));
        set @start = 1;
        set @next = 1;
        set @seed = Len(@split);
      
        set @location = CharIndex(@split, @str);
        while @location <> 0 and @index > @next
              begin
                    set @start = @location + @seed;
                    set @location = CharIndex(@split, @str, @start);
                    set @next = @next + 1;
              end;
        if @location = 0
           select   @location = Len(@str) + 1; 
      
        return Substring(@str,@start,@location-@start);
    
    end;
    go
    获取字符串包含的元素个数 以分割符号
    set quoted_identifier on;
    set ansi_nulls on;
    go
    --获取字符串包含的元素个数  以分割符号
    create function [dbo].[Get_StrArrayLength]
           ( @str NVarchar(max) ,  --要分割的字符串
             @split NVarchar(10)  --分隔符号
             )
    returns Int
    as
    begin
        declare @location Int;
        declare @start Int;
        declare @length Int;
    
        set @str = LTrim(RTrim(@str));
        set @location = CharIndex(@split, @str);
        set @length = 0;
        while @location <> 0
              begin
                    set @start = @location + 1;
                    set @location = CharIndex(@split, @str, @start);
                    set @length = @length + 1;
              end;
        return @length;
    
    end;
    go

     获取字段在数据库所有表里面 出现的表的位置

     select Object_Name(id) objName, name as colName
     from   syscolumns
     where  ( name like 'PatientID' ) and id in ( select    id
                                                  from      sysobjects
                                                  where     xtype = 'u' )
     order by objName;
  • 相关阅读:
    采用NAND Flash启动时出现Kernel panic not syncing: No init found错误
    ubuntu 11.10 安装小企鹅fcitx输入法
    UBoot中设定的bootdelay参数不起作用
    python 数据类型
    python运算符
    python符号//、%和/运算
    pytho 基本数据类型
    Python 开篇
    mmsplayer v2 java 之(mmsPlayer 播放类)
    mmsplayer v2 java 之(mmsTrack 音频类)
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/10207250.html
Copyright © 2011-2022 走看看