Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

I have a field item_code charecter varying(40) where i have id's like 1,2,21,112 etc

Now i want to add zero to make the 1 and 2 digits code to 3 digit.

Please tell me how to do that.
Posted
Comments
Sergey Alexandrovich Kryukov 4-Feb-14 23:59pm    
What's wrong with reading standard MSDN documentation?
—SA
[no name] 5-Feb-14 0:01am    
I am looking for a PgSQL query..i tagged the same.i am not looking for any sql or c# thing..
Sergey Alexandrovich Kryukov 5-Feb-14 0:42am    
Right, but why doing it in query. You need to work with numeric values, not string. Get numeric value and format it in your client's language. What is it?
—SA
[no name] 5-Feb-14 0:46am    
i have to update the table..and i am told to run the query for this..:(
Sergey Alexandrovich Kryukov 5-Feb-14 0:54am    
If you are "told to", why not asking a person who told you? :-)
—SA

1 solution

Try to find your solution here: FUNCTIONS-FORMATTING-EXAMPLES-TABLE[^]

+++++++++++++++++++++++++++++
Seeing is believing.
See for yourself my example here: http://sqlfiddle.com/#!15/45148/5[^]

I have spent much time on this. Do remember to accept the solution and vote.
 
Share this answer
 
v4
Comments
[no name] 5-Feb-14 0:09am    
I tried this:
update tbl_items set item_code = RIGHT('000', 3) where len(item_code)<3
But it's giving error
function len(character varying) does not exist
Peter Leow 5-Feb-14 0:16am    
Have you visited the link I provided?
[no name] 5-Feb-14 0:17am    
yes..i tried that also..i got this error

function to_char(character varying) does not exist
Peter Leow 5-Feb-14 0:39am    
If you have read the information provided by the link and explored the to_char() with different options, you would have found the solution yourself, try this, the output will be '001'
select to_char(1, 'FM000')
[no name] 5-Feb-14 0:44am    
What you are telling is fine..but i have to update the table ..so when i am passing the column name at the place of 1 it's giving the error which i mentioned..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900