August 28, 2006 at 1:27 pm
I have a dirty data, go figure right?
I have a doctors name that is the last name / comment. I need to trim off the / comment, last name is field, I know that this is an easy one, any suggestions?
Richard
August 28, 2006 at 1:39 pm
SELECTLEFT(value, CHARINDEX('/', value) - 1)
FROM table
That should do it...
August 28, 2006 at 2:59 pm
It works perfectly! THANK YOU!
August 31, 2006 at 7:36 am
Note: This won't work if any of the values does NOT contain a '/'.
In this case charindex(value,'/')-1 evaluates to -1 causing LEFT to blow up with an invalid length error.
You'll need to add a case something like:
select left(value, case charindex(value,'/') when 0 then len(value) else charindex(value,'/')-1 end) from table
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply