zoukankan      html  css  js  c++  java
  • 用临时表来分隔特殊符号(如逗号)的字符串

     1declare @Menu_id varchar(250)
     2declare @pos int 
     3declare @oldPos int 
     4declare @tempstr varchar(100
     5
     6
     7create table #temp_id ( id int ) 
     8
     9set @Menu_id = '60,62,63,64'
    10set @pos=1 
    11set @oldPos=1 
    12while @pos<len(@Menu_id
    13begin 
    14    set @pos=charindex(',',@Menu_id@oldpos
    15    if @pos>0 
    16    begin 
    17        set @tempstr=substring(@Menu_id,@oldpos,@pos-@oldpos
    18        set @oldpos=@pos+1 
    19    end 
    20    else 
    21    begin 
    22        set @tempstr=substring(@Menu_id,@oldpos,len(@Menu_id)-@oldpos+1
    23        set @pos=len(@Menu_id
    24    end 
    25    insert into #temp_id  values@tempstr )
    26end 
    27if len(@Menu_id)  = 1
    28    insert into #temp_id  values@Menu_id )
    29
    30select id from #temp_id
    31drop table #temp_id 
  • 相关阅读:
    leetcode -- Word Break
    [笔试题]MS 2014
    网络编程之TCP/IP各层详解
    深浅copy
    字符编码的转换
    Bytes类型
    Django之模型层(1)
    Django之模板层
    用Python操作文件
    hash(哈希)是什么
  • 原文地址:https://www.cnblogs.com/sonicit/p/1045752.html
Copyright © 2011-2022 走看看