concatenate a zero onto sql server select value shows 4 digits still and not 5(将零连接到 sql server 选择值仍然显示 4 位而不是 5)
问题描述
我的邮政编码在导入时从 excel 文件中没有为零.所以我做了一个选择,以便将 0 连接到每 4 位邮政编码的前面.
I have zip codes that on import didn't have zero from excel file. So I was doing a select in order to concatenate 0 to front of every 4 digit zip code.
我正在尝试这个,但它仍然吐出 4 个数字
I was trying this, but it still spits out 4 digits
(0 + [ZIP]) as 'fullzip'
ZIP 是 db 表中的浮点数
ZIP is a float in db table
我的完整sql
SELECT
TOP 1000
[ZIP]
,(0 + [ZIP]) as 'fullzip'
,[ZIP_Name]
,[ZIP_CountyFIPS]
,[ZIP_County]
,[ZIP_State]
,[Utility_Name]
,[Holding_Company]
,[Utility_ID]
,[GAS_LDC_Type]
,[ELEC_Non_IOU_Type]
,[Percent_of_Overlap]
,[Utility_Territory_Type]
FROM
cc.dbo.ServiceableZipCodes
WHERE
Len( [ZIP] ) = 4
推荐答案
如果 zip 是浮点数,我会转换为 char,然后做字符串数学.
If zip is a float, I'd convert to char, then do the string math.
RIGHT( '00000' + CONVERT(varchar(5),ZIP), 5)
不假设最小值4 位数字.
Doesn't assume minimum values of 4 digits.
这篇关于将零连接到 sql server 选择值仍然显示 4 位而不是 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将零连接到 sql server 选择值仍然显示 4 位而不是


- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01