Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Friday, November 22, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Data & Imports Forums - T-SQL & Queries
Forum to discuss general T-SQL questions and help with queries related to SalesLogix data. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to T-SQL & Queries | New ThreadView:  Search:  
 Author  Thread: SQL and the single quote
Brandy Iskin
Posts: 8
 
SQL and the single quoteYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 27 Jul 06 11:43 AM
fiogf49gjkf0d
I am trying to run a query on a list of accounts, but my data contains single quotes. What is the work around?
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: SQL and the single quoteYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 27 Jul 06 11:51 AM
fiogf49gjkf0d
You can escape a single quote with two consecutive single quotes.

For example, this will cause an error:

select * from contact where lastname = 'O'Brian'


But this will not:

select * from contact where lastname = 'O''Brian'  --notice the two consecutive single quotes


You can use the VBScript function in your code to replace the single quote with two consecutive single quotes:

lastname = "O'Brian"
sql = "select * from contact where lastname = '" & Replace(lastname, Chr(39), Chr(39) & Chr(39)) & "'"
'...btw, Chr(39) is a single quote character


A better approach however, is to use a parameterized query and then use parameters for your values you need to plug into the query. Then things like single quotes are not an issue.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/22/2024 9:48:43 AM