Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

Adding leading zeros in a string


I have a string of 15 characters with format 99-AA-99999-999. User can enter
any length of data at number's position. It could be
  i- 9-AA-999-9 or
 ii- 99-AA-9-9 or
iii- 9-AA-99-9
or anything but in the limit of 99-AA-99999-999.

Now depending upon user input I want to put leading 0 (zeros) in this string
as below
  i- 09-AA-00999-009 or
 ii- 99-AA-00009-009 or
iii- 09-AA-00099-009.

How can I accomplish it?


Create Table #MyTable (MyColumn varchar(20))
Insert #MyTable (MyColumn) Values ('9-AA-999-9')
Insert #MyTable (MyColumn) Values ('99-AA-9-9')
Insert #MyTable (MyColumn) Values ('9-AA-99-9')
Select Right('00' + ParseName(DotFormat,4), 2) + '-' +
  ParseName(DotFormat,3) + '-' +
  Right('0000' + ParseName(DotFormat,2), 5) + '-' +
  Right('000' + ParseName(DotFormat,4), 3) As Result
From (Select Replace(MyColumn, '-', '.') As DotFormat
From #MyTable) As x
Drop Table #MyTable


"Khurram Shahzad" <Call@hotmail.com> wrote in message


Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc