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!

Add character in string 1

Status
Not open for further replies.

jtrembla

ISP
Jul 6, 2006
104
0
0
US
Is there a function I can use that will insert a character into a specified position in a string.

For example I want to add 0 into the 2nd position of the following string

"W3B3 JSUSJJ"

so it becomes "W03B3 JSUSJJ
 
STUFF.

Ex:

Code:
Declare @Test VarChar(100)
Set @Test = 'W3B3 JSUSJJ'

Select Stuff(@Test, 2, 0, '0')

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Would the 'stuff' command work for adding 3 zeros to the front of a string that has seven digit data in a 10 digit-length field? I need to take a value of 0789654 and make it 0000789654.

Steve
 
it could but if you want all the resultset to be always 10 dig. string with leading zeroes then better use:
Code:
SELECT RIGHT(REPLICATE('0',10)+CAST(YourField as varchar(10)),10) AS Something

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Some records are 10 characters and some are only 7. I need to add the 3 zeros to the ones that are only 7.

Hope that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top