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

Remove Data to left or right of a character

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi I have data in the following format:
1111x222
33x4444
222x1111
4444x33

Is there a script I can run to remove all data to the left of the x? Sometimes I might have to remove to the right of the x too.

Thanks!

Brian
 
left of the x

select substr('table.field',1,instr('table.field','x',1)-1) from table

right of the x

select substr('table.field',instr('table.field','x',1)+1,length('table.field')) from table

-- Jason
"It's Just Ones and Zeros
 
That's what I'm talking about. I am using SQL 2000 so I had to make a few adjustments:

For Left:
Code:
select substring (table.field,1,charindex('x', table.field,1)-1) from table

For Right:
Code:
select substring(table.field,charindex('x', table.field,1)+1,len(table.field)) from table

So far it looks good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top