SQL Server中的Json值

时间:2018-02-01 16:55:59

标签: json sql-server

我想使用下面的查询删除空格。第二个(" DEF")和第三个输入值(" GHI")中有一个空格。我们如何删除空间?

原始查询:

SELECT 
    *
FROM 
   openjson('[{"value":"12","text":"ABC"},
              {"value":"31","text":" DEF"},
              {"value":"25","text":"GHI "}]', '$' )
WITH ([NUMBER] nvarchar(100) '$.text')

1 个答案:

答案 0 :(得分:0)

I used the TRIM function.

SELECT TRIM([NUMBER])
FROM openjson('[{"value":"12","text":"ABC"},
            {"value":"31","text":" DEF"},
            {"value":"25","text":"GHI "}]', '$' )
WITH ([NUMBER] nvarchar(100) '$.text')

Depending on your version of SQL Server, LTRIM() and RTRIM() can be nested to provide similar functionality.

SELECT RTRIM(LTRIM([NUMBER]))
FROM openjson('[{"value":"12","text":"ABC"},
            {"value":"31","text":" DEF"},
            {"value":"25","text":"GHI "}]', '$' )
WITH ([NUMBER] nvarchar(100) '$.text')