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

function instead of lpad

Status
Not open for further replies.

557

Programmer
Oct 25, 2004
64
US
can you tell me the function in sql server which serves the purpose of lpad of oracle

in oracle, lpad(x , 5 , '0') would return x always as a string of length 5 characters even if it's original length is lesser. 0 will be appended to it's left if it is of shorter lenght
 
You can do this using REPLICATE
e.g.

Code:
declare @x int
set @x = 10 --you want to return 00010
select replicate('0', 5 - len(@x)) + convert(varchar, @x)
not as tidy as lpad but does the same output



"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top