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 
  • 相关阅读:
    关于栈部分知识点
    面向对象--四则运算
    转型第一步
    输入输出文件版本——计算题
    作业二
    2017《面向对象程序设计》课程作业一
    第四次作业
    light oj 1079
    Light oj 1080
    Codeforces 486B OR in Matrix【水题】
  • 原文地址:https://www.cnblogs.com/sonicit/p/1045752.html
Copyright © 2011-2022 走看看