How to remove space from SQL

旧时模样 提交于 2019-12-12 06:28:51

问题


Example

col1        col 2       col3
300         Broad       ST

,(IsNUll((Cast(FLOOR(col1) as CHAR (7) )),'')  + ' ' + IsNull(col2,'') + ' ' + isnull(col3,'')) as col4

result i get is

300     Broad ST

what i want is

300 Broad St. 

there is 4 or 5 space between 300 and Broad

the data type for col1 is numeric and for col 2 and 3 is nvarchar. I don't want to change the data type.


回答1:


This looks a lot like SQL Server. If so:

stuff(coalesce(' ' + Cast(floor(col1) as varchar(7)), '') +
      coalesce(' ' + col2, '') + 
      coalesce(' ' + col3, ''),
      1, 1, '') as col4


来源:https://stackoverflow.com/questions/44006348/how-to-remove-space-from-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!