如何从SQL中删除空间 [英] How to remove space from SQL

查看:38
本文介绍了如何从SQL中删除空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例子

col1        col 2       col3
300         Broad       ST

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

我得到的结果是

300     Broad ST

我想要的是

300 Broad St. 

300 和 Broad 之间有 4 或 5 个空格

there is 4 or 5 space between 300 and Broad

col1 的数据类型是数字,col 2 和 3 的数据类型是 nvarchar.我不想更改数据类型.

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

推荐答案

这看起来很像 SQL Server.如果是这样:

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

这篇关于如何从SQL中删除空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆