473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

converting integer zipcodes to a 5 character char

hello all,

is there a quick way to convert a zipcode of type int, to a 5 character
char value ?
e.g.

declare @zip int
declare @czip char(5)
select @zip = 2109
select @czip = convert(char, @zip)
select @czip

but with @czip = 02109 instead of 2109 ?
thanks in advance

May 23 '06 #1
2 1987
SQL
Here is one way
declare @zip int
declare @czip char(5)
select @zip = 2109
select @czip = convert(char, RIGHT('00000' + CONVERT(VARCHAR,@zip),5))
select @czip

Denis the SQL Menace
http://sqlservercode.blogspot.com/

May 23 '06 #2
select substring(convert(char,100000+123),2,5)
select substring(convert(char,100000+1234),2,5)
select substring(convert(char,100000+12345),2,5)
-----
00123

(1 row(s) affected)
-----
01234

(1 row(s) affected)
-----
12345

(1 row(s) affected)

May 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Keith MacDonald | last post by:
Hello, Is there a portable (at least for VC.Net and g++) method to convert text between wchar_t and char, using the standard library? I may have missed something obvious, but the section on...
12
by: David Williams | last post by:
Hi all, i have been able to convert an ASCII character to an INT however im lost as to how to change them back. Cant find anything on the net (though im probably looking in the wrong places!)....
4
by: JJA | last post by:
I need to show data for the top 3 zipcodes for EACH of the top 5 counties. I feel totally blocked on how to make this work properly. Here is my code - anything you can suggest will be greatly...
22
by: hantie | last post by:
In my program, for reducing the complexity, the integer was stored as char, so 2 is stored as '2', which is decimal: 50 Is is possible for me to obtain the integer value of '2' in the program,...
23
by: Nikhil Patel | last post by:
Hi all, How can I convert an integer to its equivalent ascii character without using Microsoft.VisualBasic dll or any other dll(I want to reference only System.dll). Thanks. -Nikhil
156
by: Lame Duck | last post by:
Hi Group! I have a vector<floatvariable that I need to pass to a function, but the function takes a float * arguement. That's OK, I can convert by doing &MyVector.front(), but when I get back a...
5
by: Hemant Shah | last post by:
Folks, How can I convert date/time/timestamp to an integer? According to UDB 8.1 docs that I have, INTEGER('1964-07-20') should return 19640720, but when I run the SQL statement I get...
3
by: rob.ahlberg | last post by:
I got an integer what I trying to use with allegro function textout_ex() but it wants an char/char* as arg... And I really don't know how to cast it to one...
9
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.