SQL查询在值之间添加空格

时间:2022-07-30 07:59:54

Can you help me with the sql update query used to add spaces in a field.

你能帮我解决用于在字段中添加空格的sql update查询吗?

Eg. "INC MP99" Result should be like "IN C MP 99"

例如。 “INC MP99”结果应该像“IN C MP 99”

There are 4 spaces in between IN & C and MP & 99 , Between C and MP it has to be 5 spaces.

在IN和C以及MP和99之间有4个空格,在C和MP之间它必须是5个空格。

Thanks

1 个解决方案

#1


1  

Extract parts of the data using SUBSTRING ( expression ,start , length ) or equivalent and then put it back together.

使用SUBSTRING(表达式,开始,长度)或等效物提取部分数据,然后将其重新组合在一起。

DECLARE @data nvarchar(50) = 'INC MP99'
SELECT CONCAT(SUBSTRING(@data,0,1),'    ', SUBSTRING(@data,2,5), '     ', SUBSTRING(@data,6,50) ) 

This will work with MS SQL Server. If you are looking for other database syntax, then you will have to adjust.

这适用于MS SQL Server。如果您正在寻找其他数据库语法,那么您将不得不进行调整。

#1


1  

Extract parts of the data using SUBSTRING ( expression ,start , length ) or equivalent and then put it back together.

使用SUBSTRING(表达式,开始,长度)或等效物提取部分数据,然后将其重新组合在一起。

DECLARE @data nvarchar(50) = 'INC MP99'
SELECT CONCAT(SUBSTRING(@data,0,1),'    ', SUBSTRING(@data,2,5), '     ', SUBSTRING(@data,6,50) ) 

This will work with MS SQL Server. If you are looking for other database syntax, then you will have to adjust.

这适用于MS SQL Server。如果您正在寻找其他数据库语法,那么您将不得不进行调整。