我想使用下面的查询删除空格。第二个(" DEF")和第三个输入值(" GHI")中有一个空格。我们如何删除空间?
原始查询:
SELECT
*
FROM
openjson('[{"value":"12","text":"ABC"},
{"value":"31","text":" DEF"},
{"value":"25","text":"GHI "}]', '$' )
WITH ([NUMBER] nvarchar(100) '$.text')
答案 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')