博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
拆分json格式数组
阅读量:4339 次
发布时间:2019-06-07

本文共 3283 字,大约阅读时间需要 10 分钟。

把转换成

 

declare @key nvarchar(3);declare @data nvarchar(max);declare    @code nvarchar(50) declare    @countrycn nvarchar(100) declare    @countryus nvarchar(100)declare    @provincecn nvarchar(100) declare    @provinceus nvarchar(100) declare    @citycn nvarchar(100) declare    @cityus nvarchar(100) declare    @cityid nvarchar(50) declare @str nvarchar(1000);declare my_cursor cursor --定义游标for (select [key] from airportdemo  ) -- 把数据集导入游标open my_cursor  -- 打开游标fetch next from my_cursor into @key  --把游标中第一条放到变量key中while @@fetch_status=0      --循环遍历begin     select @code='',@countrycn='',@countryus='',@countrycn='',@provincecn='',@provinceus='',@citycn='',@cityus='',@cityid='';--初始化变量            select @data = data from airportdemo where [key]=@key;    print @data ;    select @code = [key] from dbo.GF_StringSplit(@data);--根据data获得key,data数据表,并把key赋给@code;    select @str = data from dbo.GF_StringSplit(@data);--@str获得data数据    declare @firstData nvarchar(1000);     select @firstData= [string] from dbo.uf_StrSplit(@str,',') where str_id = 1;    declare @secondData nvarchar(1000);     select @secondData= [string] from dbo.uf_StrSplit(@str,',') where str_id = 2;--把data按 ,分割开来     declare @thirdData nvarchar(1000);    select @thirdData =[string] from dbo.uf_StrSplit(@str,',') where str_id = 3;    declare @thirdCount int;    set @thirdCount = dbo.Get_StrArrayLength(@thirdData,'|');    declare @count int ;    set @count = dbo.Get_StrArrayLength(@secondData,'|');    if(@count = 4)    begin        select @countrycn= [string] from dbo.uf_StrSplit(@str,',') where str_id = 3;        select @countryus = [string] from dbo.uf_StrSplit(@secondData,'|') where str_id = 1;--把 CHINA|阿里(NGQ)|97 阿里按'|'来分割 ,取下标为1的数据        set       @cityus=substring(@firstData,2,len(@firstData)-1);        select @cityid = [string] from dbo.uf_StrSplit(@secondData,'|') where str_id = 3;         select @citycn = [string] from dbo.uf_StrSplit(@secondData,'|') where str_id = 4;             end    else if(@thirdCount=4)    begin         select @countrycn= [string] from dbo.uf_StrSplit(@str,',') where str_id=4;        select @countryus = [string] from dbo.uf_StrSplit(@thirdData,'|') where str_id = 1;        select @cityid = [string] from dbo.uf_StrSplit(@thirdData,'|') where str_id = 3;                 select @cityus = substring(@firstData,2,len(@firstData)-1);                select @citycn = [string] from dbo.uf_StrSplit(@thirdData,'|') where str_id = 4;        select @provincecn = [string] from dbo.uf_StrSplit(@str,',') where str_id=5;        select @provinceus = [string] from dbo.uf_StrSplit(@str,',') where str_id=2;    end    else     begin         select @cityid=[string] from dbo.uf_StrSplit(@firstData,'|') where str_id = 3;        select @citycn=[string] from dbo.uf_StrSplit(@firstData,'|') where str_id = 4;        select @countryus=[string] from dbo.uf_StrSplit(@firstData,'|') where str_id = 1;    end    insert into dbo.TurnAirPort(code, countrycn, countryus, provincecn, provinceus, citycn, cityus, cityid) values(@code, @countrycn, @countryus, @provincecn, @provinceus, @citycn, @cityus, @cityid);--把数据插入数据表    fetch next from my_cursor into @key; endclose my_cursor --关闭游标deallocate my_cursor  --删除游标

 

转载于:https://www.cnblogs.com/hejinyang/archive/2013/05/13/3075983.html

你可能感兴趣的文章
关于STM32F405的GPIO中断问题
查看>>
(FFOS Gecko & Gaia) OTA - 结束篇
查看>>
Linux服务器时间相关命令记录
查看>>
SVN配置使用
查看>>
.net基础复习之一
查看>>
网页的缩放,适配以及移动的适配!
查看>>
[SCM]源码管理 - Perforce命令行
查看>>
简单的csh实例
查看>>
jenkins2 pipeline插件的10个最佳实践
查看>>
yii2关闭(开启)csrf的验证
查看>>
mysql 隔离性与隔离级别
查看>>
css选择器
查看>>
ckeditor自定义图片上传,结合EXT JS
查看>>
Java编程规范整理
查看>>
JS - this 总结
查看>>
numpy.argmin 使用
查看>>
[设计模式]访问者模式
查看>>
Hadoop运维操作
查看>>
RPN(region proposal network)之理解
查看>>
Flask最强攻略 - 跟DragonFire学Flask - 第九篇 Flask 中的蓝图(BluePrint)
查看>>