Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a String

Status
Not open for further replies.

bjr149

Programmer
Jul 18, 2005
26
US
I have a string thats 50 characters. If the length of the string is 14 then i can take the first 14 characters. Which works fine...

set @InvoiceLength = LEN(@InvoiceNumber)
If @InvoiceLength < 15
begin
set @InvoiceNumberFormatted = SUBSTRING(@InvoiceNumber,1,14)
End

If the String length is Greater than 14 then i need to right justify the string and take the last 14 characters. How do i do this part. Thanks.
 
You can do the same strick as with numbers.

Code:
Declare @Temp VarChar(50)

Set @Temp = 'Hello World'

Select Right(Replicate(' ', 14) + @Temp, 14)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top