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

Updating part of a string

Status
Not open for further replies.

mebenz

IS-IT--Management
Jun 7, 2007
88
CA
I have field values: 3310XXX101000, 3310XXX111000, 3310XXX115000 etc. I would like to update these values and change the first 4 characters to 2188 to yield 2188XXX101000, 2188XXX111000 etc.

Could I use the substring in a set function?
 
What about replace?

Code:
[COLOR=blue]Declare[/color] @Temp [COLOR=blue]VarChar[/color](100)

[COLOR=blue]Set[/color] @Temp = [COLOR=red]'3310XXX101000, 3310XXX111000, 3310XXX115000'[/color]

[COLOR=blue]Select[/color] [COLOR=#FF00FF]Replace[/color](@Temp, [COLOR=red]'3310'[/color], [COLOR=red]'2188'[/color])

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
These 3 were just examples. I could have about 50 different possible field values. I want to be able to replace the first 4 characters of all these fields with '2188.'
 
Can you show us how your data is structured (table layout)? Also, show some sample data. With this information it should be easier for us to help you.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
This works.
Code:
declare @temp varchar(50)

set @temp = '2188' + substring('sfkadjsdajfsadj', 4, 50)

print @temp
djj
 
Code:
SELECT REPLACE(YourField,LEFT(YourField,4),'2188')
       FROM YourTable
(not tested)

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top