[{ “键”: “移动设备”, “值”: “9100617634”},{ “键”: “电子邮件”, “值”: “balajirao1@ziaff.in”}]
上面的表示表格的一列中的值。 我想要两个名为mobile和email的列,其中值分别为9000617634,balajirao @ ziraff。 如何进入sql server。
见下文。
mobile Email
------ ------------
9100617634 balajirao1@ziaff.in
答案 0 :(得分:0)
你可以使用Pivot Function将行值转换为列, 以下是实施的静态代码
SELECT * FROM(
SELECT
columns_name
FROM
table_name
) M
PIVOT (MAX(Key) FOR table_name IN (mobile ,Email))AS P ;
答案 1 :(得分:0)
那很难做到这很有趣:)
--initial string
declare @s1 varchar(1000) = (select '[{"key":"Mobile","value":"9100617634"},{"key":"Email","value":"balajirao1@ziaff.in"}]')
--selecting first part and second part of string
declare @mobile varchar(100) = (select right(left(@s1,charindex('}',@s1)-1),len(left(@s1,charindex('}',@s1))) - charindex(':',left(@s1,charindex('}',@s1)))-1))
declare @mail varchar(100) = (select right(@s1,charindex(':',reverse(@s1))-1))
--getting rid of extra characters
set @mobile = (right(@mobile, len(@mobile) - charindex(':',@mobile)))
set @mail = (left(@mail, len(@mail) - charindex('}',reverse(@mail))))
--getting rid of double quotes
set @mobile = replace(@mobile,'"','')
set @mail = replace(@mail,'"','')
--selecting data
select
@mobile as Mobile,
@mail as Mail
结果如下:
移动邮件
9100617634 balajirao1@ziaff.in
答案 2 :(得分:0)
选择 当[MOBILE / PHONE]喜欢'[a-z]%'然后null [MOBILE / PHONE]结束为[MOBILE / PHONE]时, 当ISNUMERIC(email)= 0然后EMAIL以EMAIL结尾时的情况 从 ( 选择 REPLACE(SUBSTRING(右(右(左(AC.Communication,charindex('}',AC.Communication)),len(左(AC.Communication,charindex('}',AC.Communication))) - charindex(' :”,左(AC.Communication,CHARINDEX( '}',AC.Communication)))),LEN(右(左(AC.Communication,CHARINDEX( '}',AC.Communication)),LEN(左(AC .communication,charindex('}',AC.Communication))) - charindex(':',left(AC.Communication,charindex('}',AC.Communication))))) - CHARINDEX(':',right (左(AC.Communication,charindex('}',AC.Communication)),len(左(AC.Communication,charindex('}',AC.Communication))) - charindex(':',left(AC。通信,charindex('}',AC.Communication)))))),2,CHARINDEX(']',AC.Communication)),''}','')AS [MOBILE / PHONE], REPLACE(REPLACE(左(右(AC.Communication,CHARINDEX( ':',反向(AC.Communication))),LEN(右(AC.Communication,CHARINDEX( ':',反向(AC.Communication)))) -charindex('}',reverse(右(AC.Communication,charindex(':',reverse(AC.Communication)))))),':'',''),''','')AS EMAIL
从DimAccountContact作为AC