Solved

Stored procedures with ' in parameter

Posted on 1998-12-02
6
219 Views
Last Modified: 2010-03-19
I have a stored procedure that includes a parameter for a
person's last name. There are some last names with an apostophe  in them, like O'Leary, which cause errors in the stored procedure.
Specifics: @last_name varchar (30)
Line in the SQL statement: And Last_name like '"+@last_name+"%'
This works fine for all names except those like O'Leary.
Any ideas ?

0
Comment
Question by:vd
  • 3
  • 3
6 Comments
 
LVL 1

Accepted Solution

by:
kponder earned 100 total points
ID: 1092035
Change all occurances of ' in the name to '' (that is 2 's)




0
 

Author Comment

by:vd
ID: 1092036
Thanks. I don't think that would work because users wouldn't expect to have to
search for  O"leary instead of  O'leary....

(Sorry about the delay in response, there was a server problem at Exp. Exch.)

0
 
LVL 1

Expert Comment

by:kponder
ID: 1092037
1. If you are using a custom front end (VB app?), you can
   have the code change the apostrophes for you.

2. Or try this:  And Last_name like @last_name+ '%'

3. If either of these work,  could you post the entire
   SQL statement?

Thanks
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 1

Expert Comment

by:kponder
ID: 1092038
Oops

3. If Neither of these work,  could you post the entire
   SQL statement?

0
 

Author Comment

by:vd
ID: 1092039
Do you have some sql that would change all embedded 's to "s in a particular column?  
0
 

Author Comment

by:vd
ID: 1092040
Thanks. Yes, this approach works. I created a stored procedure to do the conversion;
the front-end guy is making appropriate changes there.

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

860 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