本文介紹了將零連接到 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 個數(shù)字
I was trying this, but it still spits out 4 digits
(0 + [ZIP]) as 'fullzip'
ZIP 是 db 表中的浮點數(shù)
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 是浮點數(shù),我會轉(zhuǎn)換為 char,然后做字符串數(shù)學.
If zip is a float, I'd convert to char, then do the string math.
RIGHT( '00000' + CONVERT(varchar(5),ZIP), 5)
不假設(shè)最小值4 位數(shù)字.
Doesn't assume minimum values of 4 digits.
這篇關(guān)于將零連接到 sql server 選擇值仍然顯示 4 位而不是 5的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!