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!

Adding to strings

Status
Not open for further replies.

MarkEmerson

Programmer
Jul 10, 2003
35
GB
Hello people,

I have reference numbers for staff that vary from 1-4 characters long. Basically I want to make all numbers 7 characters long by adding 0's to the front of the number. The field is varchar(7).

How can i do this?

Thanks
 
select @curVal = '123'

select @curVal = replicate('0',7-len(@curVal))

print @curVal

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
oopps...

select @curVal = replicate('0',7-len(@curVal)) + @curVal

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top