Link to home
Create AccountLog in
Avatar of andyw27
andyw27

asked on

Help with Where clause

Hi,

I’m trying to conduct a SQL statement.  I would like to include a LIKE clause.  But instead of applying the clause to the entire string I would only like it to compare a portion of the string

For example I have this string:
CS00324522 | test1 / random text1

And from this I need to construct a WHERE statement that would find this:

CS00324522 | test1 / random text2

The | and / characters are common to all strings in the database.  However the length of the strings between each of the characters varies with each row.

I guess I need to extract everything to the left of the | characters so the SQL looks like

Where row1 LIKE CS00324522 |

Any ideas if this could be achieved?
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Select  * from table where left(fieldname, instr(fieldname,"|")-1) like 'CS00324522'

Hope this helps
SELECT * FROM myTable WHERE myStrFld LIKE "CS00324522*";
andyw27:  Is there a problem?