zoukankan      html  css  js  c++  java
  • sql 语句

    declare @strtrannote nvarchar(100);
    declare @strlocation nvarchar(100);
    declare @tempstr nvarchar(100);
    set @strtrannote='a*b*'set @strlocation='1*2*';
    set @tempstr=@strlocation
    DECLARE @Index int;
    DECLARE @Left nvarchar(50);
    WHILE CHARINDEX('*',@strtrannote> 0--返回字符串中指定表达式的起始位置
     BEGIN
      
    SELECT @Index = CHARINDEX('*',@strtrannote);--返回字符串中第一个"&"的起始位置
      SELECT @Left = LEFT(@strtrannote,@Index-1);--从左边开始,取得字符串左边指定个数的字符(第一个值)
      --update TranNote set packlist_id=@packlist_id where TranNotekey=@LEFT and website=@website;
        DECLARE @Index2 int;
        
    DECLARE @Left2 nvarchar(50);
      
    set @strlocation=@tempstr
        
    WHILE CHARINDEX('*',@strlocation> 0--返回字符串中指定表达式的起始位置
            BEGIN
                
    SELECT @Index2 = CHARINDEX('*',@strlocation);--返回字符串中第一个"&"的起始位置
                SELECT @Left2 = LEFT(@strlocation,@Index2-1);--从左边开始,取得字符串左边指定个数的字符(第一个值)
                    print(@left);
                    
    print(@left2);
                
    SELECT @strlocation = REPLACE(@strlocation,@Left2+'*','');--将左边已经取出的部分替换为空
            END
      
    SELECT @strtrannote = REPLACE(@strtrannote,@Left+'*','');--将左边已经取出的部分替换为空

     END

    显示结果:

    a
    1
    a
    2
    b
    1
    b
    2

  • 相关阅读:
    分布式事务-第一刀
    Qt
    自描述C++部分面试题集
    读书笔记6.21
    STL vector容器 和deque容器
    C++ STL框架
    C++ 多态
    C++ 虚继承
    C++ 类的继承和派生
    C++ 类中的函数重载
  • 原文地址:https://www.cnblogs.com/lfzwenzhu/p/1332905.html
Copyright © 2011-2022 走看看