Link to home
Start Free TrialLog in
Avatar of tshaikh
tshaikh

asked on

How to protect a forward slash in a sql string

I need to retrieve records with the / from a table. However, I am using a stored procedure with string variable

'Select * from table a where code in ('/')' <=== all single quotes and I do not return any rows.  Please advice.  I've tried code in (''//'').

Thanks
SOLUTION
Avatar of pique_tech
pique_tech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tshaikh
tshaikh

ASKER

I am trying to retrieve records where the / is in the field code.

Thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or:

SELECT     *
FROM         a
WHERE     (code  LIKE '%' + CHAR(47) + '%')


whatever u need
I think what you want is

SELECT *
FROM a
WHERE code Like '%/%'

This will return all records where the field [code] contains the character '/' even if it's the only character in the field.  

Hammadian2's suggestion above will only return those records where '/' is all that appears in the field [code].
(Hammadian2 types faster than I do.)
Avatar of tshaikh

ASKER

Thank you both for such a quick reply.  I used char(47).