zoukankan      html  css  js  c++  java
  • SQLSERVER 拆分拼接字符串

    SQLSERVER 拆分拼接字符串,WHILE循环输出

     1 DECLARE @Items VARCHAR(1000)
     2 SET @Items='148,149,150,151' +',' 
     3 DECLARE @ItemIndex INT
     4 set @ItemIndex=CHARINDEX(',',@Items)
     5  
     6 WHILE(@Items!=',' AND @ItemIndex>0)
     7 BEGIN
     8     PRINT LEFT(@Items,@ItemIndex-1)
     9     SET @Items=RIGHT(@Items,LEN(@Items)-@ItemIndex)
    10     SET @ItemIndex=CHARINDEX(',',@Items)
    11 END

    拆分字符串并插入临时表

    declare @s varchar(100),@sql varchar(1000)
    set @s='1,2,3,4,5,6,7,8,9,10'
    set @sql='select col='''+ replace(@s,',',''' union all select ''')+''''
    PRINT @sql
    exec (@sql)

     附件配置显示文档并下载

    (SELECT  '<a  href="../' + ATTACH.FILEPATH + '"  aid="'+ CAST(ATTACH.AID AS VARCHAR) + '" aname="' + ATTACH.FILETILE+ '"  atype="' + ATTACH.FILETYPE + '">' + ATTACH.FILETILE+ '</a><br/>'
     FROM    dbo.SYS_ATTACHMENT ATTACH
     WHERE   CHARINDEX(',' + CAST(ATTACH.AID AS VARCHAR) + ',',',' + a.FILES + ',') > 0 FOR  XML PATH('') ,TYPE).value('.', 'NVARCHAR(MAX)') 
     AS FILESNAME
  • 相关阅读:
    django-高级
    django-模板
    django-视图
    django笔记一
    redis、mysql、mongodb数据库
    Scrapy-redis分布式+Scrapy-redis实战
    python2 'ascii'编码问题
    【java8新特性】方法引用
    java浮点数运算无法精确的问题
    java中Array和ArrayList区别
  • 原文地址:https://www.cnblogs.com/zp0818/p/9628416.html
Copyright © 2011-2022 走看看