|
-
Nov 30th, 2002, 03:03 AM
#1
Thread Starter
Junior Member
TSQL help neede for converting numbers
Hi vb experts!
I am using vb6 + sql2000. How can I convert a number (integer or decimal) to CHAR format, where the length is 12 and I have to fill the empty characters with 0s. Ex: 128 - 000000128,00 or 1223.2 - 000001223,20. I can write an algorithm to do that, but I'm pretty sure that there are easier ways. Thx for your help!
-
Nov 30th, 2002, 06:29 PM
#2
Junior Member
Hello yo-vb
Ok I would do that with a format statement.
VB Code:
Private Function FormatNum(ByVal iNum As Integer) As String
Dim sRtn As String
sRtn = Format(iNum, "000000000000")
FormatNum = sRtn
End Function
I think that would be the easiest way to handle that one.
Hope that helps a little.
Best,
Roger
VB6.0 SR5 & VB.Net Pro
-----------------------------------------------
Do or do not, there is no try!
-
Nov 30th, 2002, 08:34 PM
#3
He's looking for the T-SQL way to do it. Try this:
SELECT RIGHT('000000000000' + CONVERT(VARCHAR(12), YourNumField), 12) AS FormattedField FROM YourTable etc. etc.
"It's cold gin time again ..."
Check out my website here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|