Hi,
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?
TIA
Kay
Create Table #MyTable (MyColumn varchar(20))
go
Insert #MyTable (MyColumn) Values ('9-AA-999-9')
Insert #MyTable (MyColumn) Values ('99-AA-9-9')
Insert #MyTable (MyColumn) Values ('9-AA-99-9')
go
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
go
Drop Table #MyTable
Tom
"Khurram Shahzad" <Call
@hotmail.com> wrote in message
news:e1UCTJEjHHA.3512@TK2MSFTNGP06.phx.gbl...
> Hi,
> 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?
> TIA
> Kay