473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Formatting a Number

Hi,

I want format a number CU00001(ie 1 to 00001)
please help me..

thanking you
Mar 10 '08 #1
4 1925
gpl
152 100+
Hi,

I want format a number CU00001(ie 1 to 00001)
please help me..

thanking you
Assuming that you always want a 5-digit number, prepend your value with 5 0s then take the rightmost 5 characters, something like

Expand|Select|Wrap|Line Numbers
  1. Select Right('00000' + Convert(varchar(5), @MyVar), 5)
If you are going to use this multiple times, then wrap it up in a handy function
Graham
Mar 10 '08 #2
amitpatel66
2,367 Expert 2GB
Hi,

I want format a number CU00001(ie 1 to 00001)
please help me..

thanking you
Could you provide sample data before formatting and how you want after formatting?
Mar 11 '08 #3
Could you provide sample data before formatting and how you want after formatting?

Hi,
I got the answer. Thank you for ur repling. I am new to stored procedure..

Thank you
Mar 11 '08 #4
Could you provide sample data before formatting and how you want after formatting?

Hi,
I got the answer. Thanks for repling. I am new to stored procedure..


Here is the simple procedure which is used to add a customerdetails

Create procedure [dbo].[AddCustomer]
@FName nvarchar(50),
@LName nvarchar(30),@Add1 nvarchar(50),
@Add2 nvarchar(50),@City nvarchar(50),
@State nvarchar(20),@Pincode nvarchar(6),
@Phone nvarchar(25),@Country nvarchar(20),
@Email nvarchar(50),@Type nvarChar(1),
@CardNo nvarchar(50)

as
begin
declare
@id nvarchar(12);
-- if customerID exists means get max value and increment that value
-- else add First value
if (select count(*) from CustomerDetails)>0
begin;
select @id=max(right(ID,5)) from CustomerDetails
set @id=right(@id,5)
set @id=cast(@id as float)+1
set @id='CU'+Right('00000' + Convert(varchar(5), @id), 5)
end;
else
set @id='CU00001'


Insert into CustomerDetails values (@id,@FName,@LName,@Add1,@Add2,@City,@State,@Pinco de
,@Phone,@Country,@Email,@Type,@CardNo)

end


Thank you
Mar 11 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Thomas Philips | last post by:
Consider the following simple dictionary e={1:'one', 2: 'two'} e >>>'one' However, If I attempt to print e using a formatted string print " %(1)s" %e, I get a KeyError: '1'
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
4
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
4
by: John Sutor | last post by:
I need some code that, on each keyup event, will take all of the numbers typed into the text box and format as they type to look like this 100 1,000 10,000 100,000 1,000,000 John S
7
by: ilona | last post by:
Hi all, I store phone numbers in the database as 123447775665554(input mask is used for input, and some numbers have extensions), and I also know from db if the number is Canadian, US, or some...
2
by: jodyblau | last post by:
I'm not certain that what I am trying to do is possible; in any event I haven't been able to figure it out. Here is what I am trying to do: I have one table that has a list of cases I'm working...
7
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
14
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my...
6
by: Jack | last post by:
Hi there, Given a standard .NET string, does anyone know what the regular expression would be to locate each (optional) formatting item in the string (or more likely does anyone have a link that...
5
by: Berryl Hesh | last post by:
Requirements for a field that represents an EmployeeNumber: · The field is always 6 characters long, and is stored as a 'string' in the db o All characters must be digits § ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.