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

Padding character variables with zeros or spaces in SQL Server

Status
Not open for further replies.

sivi

IS-IT--Management
Nov 27, 2002
27
GB
I would be grateful if someone could advice me on padding character variavbles with zeros or spaces in SQL Server

Many Thanks
 
USE pubs

GO

SELECT RTRIM(au_lname) + ',' + SPACE(2) + LTRIM(au_fname)

FROM authors

ORDER BY au_lname, au_fname

GO


Also check the REPLICATE function...
REPLICATE(character_expression, integer_expression) ---------------------------------------
[turkey] HAPPY THANKSGIVING!!!! [turkey]
mikewolf@tst-us.com
 
Mike

Thanks,

I need to pad to a required length and this length is variable. Depends on how many characters out of 15 (field length) are populated on the table, the rest must be padded with '0' or spaces on extracting this data from the table.

Cheers
Sivi
 
USe len to find out the len of th string and then replicate to get a string with the right number of 0 or spaces and then concatenate the field with the resuilts of replicate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top