zoukankan      html  css  js  c++  java
  • SQL Server将列以分隔符分割后存到临时表

    begin
        if object_id('tempdb..#t') is not null  drop table #t; 
        create table #t
        (
            filepath nvarchar(300)
        );
        declare @filePathStr nvarchar(max),
            @endIndex int = 1,
            @currentFilePath nvarchar(300),
            @sql nvarchar(max);
        set @filePathStr = '1;235;67456;2667;35;3;67';
        set @filePathStr += ';';
        while CHARINDEX(';',@filePathStr) > 0
        begin
            set @endIndex = CHARINDEX(';',@filePathStr) - 1;
            print(@endIndex);
            set @currentFilePath = SUBSTRING(@filePathStr,1,@endIndex);
            print(@currentFilePath);
            set @filePathStr = SUBSTRING(@filePathStr,@endIndex + 2,LEN(@filePathStr) - LEN(@currentFilePath));
            print(@filePathStr);
            insert into #t(filepath)
                select @currentFilePath;
        end;
        select * from #t;
    end;

     运行后结果截图:

    2015年10月-2016年3月 总计:5个月.
    2016年11月-2017年6月 总计:7个月.
    2017年7月-2018年4月 总计:9个月.
    2018年5月-2018年5月 总计:1个月.
    2018年6月-2018年12月 总计:6个月.
    2019年1月-2019年12月 总计11个月.
    2020年2月-2021年2月 总计13个月.
    所有总计:5+7+9+1+6+11+13=52个月(4年4个月).
    本人认同二元论.我是理想主义者,现实主义者,乐观主义者,有一定的完美主义倾向.不过,一直都是咸鱼(菜鸟),就算有机会,我也不想咸鱼翻身.(并不矛盾,因为具体情况具体分析)
    英语,高等数学,考研,其他知识学习打卡交流QQ群:946556683
  • 相关阅读:
    android 2.3 bug android 4.x bug
    设计高性能CSS3动画的几个要素
    开启硬件加速 解决页面闪白 保证动画流畅
    取消input在ios下,输入的时候英文首字母的默认大写 android 上去掉语音输入按钮
    JS中的类型检测
    CSS的一点知识
    HTML Canvas
    HTML DOM Table 对象
    只是有所了解的语言
    骑士巡游问题
  • 原文地址:https://www.cnblogs.com/JimmySeraph/p/11083082.html
Copyright © 2011-2022 走看看