vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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/ |
| ||||
| 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) |