[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to protect a forward slash in a sql string

Posted on 2004-11-03
7
Medium Priority
?
4,060 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:tshaikh
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Assisted Solution

by:pique_tech
pique_tech earned 400 total points
ID: 12488753
Is the single character '/' all that appears in the field named [code] in your database?  Or are you trying to retrieve records where the '/' is contained in the field [code]?
0
 

Author Comment

by:tshaikh
ID: 12488774
I am trying to retrieve records where the / is in the field code.

Thanks
0
 
LVL 5

Accepted Solution

by:
Hammadian2 earned 1600 total points
ID: 12488801
SELECT     *
FROM      a
WHERE     (code = CHAR(47))
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:Hammadian2
ID: 12488809
Or:

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


whatever u need
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12488822
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].
0
 
LVL 12

Expert Comment

by:pique_tech
ID: 12488827
(Hammadian2 types faster than I do.)
0
 

Author Comment

by:tshaikh
ID: 12488859
Thank you both for such a quick reply.  I used char(47).

0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question