format char fields to have leading zeroes
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


format char fields to have leading zeroes Expand / Collapse
Author
Message
Posted 10/6/2009 2:30:45 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/6/2009 3:10:30 PM
Posts: 2, Visits: 3
I am new to Teradata, so please ignore my lack of knowledge. Any help would be greatly appreciated.
I have char(10) field in a table, which holds a number. This number in most cases is 10 character long but not in all cases. So in case if the number is less than 10 characters(for example 000123456), I want to be able to convert it by adding a leading zero to it. I am doing something like following, but it is not converting correctly. I am doing the select to have the data exported in a file as fast export.

select cast(col1 as integer) (format '9(10)') from tablex

P.S. col1 is of type char

Please help.


Thank you.
Post #17043
Posted 10/6/2009 2:58:14 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: Yesterday @ 3:55:54 AM
Posts: 111, Visits: 263
If it is already a character, and there is no sign, then just put the required number of zeroes on the front:

Select Substr('0000000000',1,10-Chars(Trim(col1))||
Trim(col1) (Char(10))
From TableX
;

If there is any possibility of a sign (presumably positive!). and you want to do it as a number:

Select Cast((Cast(Col1 As Integer) (Format '9(10)')) As Char(10) )
From TableX
;

Note that if the number is negative, you have just put it out as positive!
Post #17044
Posted 10/6/2009 3:16:16 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/6/2009 3:10:30 PM
Posts: 2, Visits: 3
jimm,

Thank you so very much for the solutions.
Both work fine in my case, since there is no sign involved.


Thank you.
Post #17045
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 2:47pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.094. 9 queries. Compression Disabled.