If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Ignore zeros on the left of a number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-29-04, 07:32
rasha rasha is offline
Registered User
 
Join Date: Feb 2004
Location: Egypt
Posts: 12
Ignore zeros on the left of a number

I am trying to generate a unigue code for every user in my table. This code sholud look like:
"S" & Current Year & Unique Number.
And this Unique Number consists of 5 digitis such that:
First ---> 00001 ----> SXX00001
Second ---> 00002 ----> SXX00002
Third ---> 00003 ----> SXX00003
Fourth ---> 00004 ----> SXX00004
and so on.....
What I do is that I select the last 5 digits of the code
and convert it to integer and and then add 1. It works but the result will be ----> SXX5 and not ----> SXX00005,
meaning it ignores the zeros on the left?
Can any body help me to fix this code such that the new id does not ignore the zeros on the left
My code is:
select @Mv = RIGHT(SID, 5)From SRegisteration
set @Mv = CAST(@Mv AS int) + 1

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-29-04, 14:19
aus aus is offline
Registered User
 
Join Date: Oct 2003
Location: Denver, Colorado
Posts: 137
Re: Ignore zeros on the left of a number

To get the code without ignoring the zeros, use the LPAD function.
Code:
LPAD(CAST(@Mv AS UNSIGNED)+1, 5, '0')
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On