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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Padding

Status
Not open for further replies.

msalvador

Programmer
Joined
Nov 13, 2001
Messages
33
Location
IT
I've to pad a string

my table is

PLU( barcode varchar(50),description(50))

and contains:

barcode |description
----------------------
000123456|Potatoes
002222222|Milk
222222222|Coke

i've to do the padding for the barcode

Select barcode,description from PLU

the resultset must be

barcode |description
----------------------
123456 |Potatoes
2222222 |Milk
222222222|Coke

anyone known if there are a function or a stored procedure

 
One result is right justified left zero filled. The other is left justified right space filled. If that's what you want then try this:

SELECT SUBSTRING(barcode,PATINDEX('%[^0]%',barcode),<whatever the width of barcode is>) AS barcode, description
FROM <YourTable> JHall
 
wonderful it's work very well
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top