473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Single Quote In Variable

233 100+
I have a stored procedure containing the following,

SELECT @cntctownerkey = (SELECT CustKey FROM tarCustomer WHERE CustName = @account)

However, it does not return a value because value of @account contains a single quote. How can I handle this given I can't escape the quote because I do not know if/when one will occur in @account?
Mar 7 '08 #1
4 6217
ck9663
2,878 Expert 2GB
I have a stored procedure containing the following,

SELECT @cntctownerkey = (SELECT CustKey FROM tarCustomer WHERE CustName = @account)

However, it does not return a value because value of @account contains a single quote. How can I handle this given I can't escape the quote because I do not know if/when one will occur in @account?

What's your CustName look like? Does it has the quote? If you need to remove the quote from the value of @account, just use the REPLACE function.

-- CK
Mar 7 '08 #2
mcfly1204
233 100+
What's your CustName look like? Does it has the quote? If you need to remove the quote from the value of @account, just use the REPLACE function.

-- CK
@account should exactly match CustName. This being the case, I would have to use the REPLACE function for both @account and CustName then.
Mar 10 '08 #3
mcfly1204
233 100+
What's your CustName look like? Does it has the quote? If you need to remove the quote from the value of @account, just use the REPLACE function.

-- CK
So, I changed the query to,

SELECT @account = REPLACE(@account,"'"," ")

SELECT @cntctownerkey = (SELECT CustKey FROM tarCustomer WHERE REPLACE(CustName, "'"," ") = @account)

however that does not seem to be right. Any thoughts on how I can replace the apostrophe in both the selection from the column CustName as well as @account?
Mar 10 '08 #4
ck9663
2,878 Expert 2GB
Paste this on your query analyzer:

Expand|Select|Wrap|Line Numbers
  1. declare @name varchar(50)
  2.  
  3.  
  4. set @name = 'clark''kent'
  5.  
  6. select @name, replace(@name,'''','')

Notice that the quote disappeared. On the replace function, I use 4 quotes in the second argument.

Happy coding.

-- CK
Mar 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Joel | last post by:
Hi, I incorporated a function in my code that whenever I use a string variable in an sql statement if the string contains a single quote it will encase it in double quotes else single quotes. ...
3
by: Jason | last post by:
I have several tables with quite a few fields and I'm getting errors when trying to insert records with single quotes in the data like: name = John O'Henry or a city name of O'Fallen So I went...
28
by: rajendra.stalekar | last post by:
Hi Folks!!! I have a string let's say "hi" and got to reverse it using just a single variable for swapping, how do I do it? Regards, Rajendra S.
4
by: nirjhar.oberoi | last post by:
Hi, This is my first post on this group! i am beginner lever C programmer. I am trying to add two numbers or multiply them using a single variable! Your are not allowed to use Unions or any...
8
by: Marina Levit [MVP] | last post by:
I've scoured google, but apparently none of the suggestions actually work. I have the following. type of XPATH query "SomeNode[SomeAttribute = 'abc's search'" Now, I've tried doing this: ...
6
by: Nirjhar Oberoi | last post by:
Hi, Can you add two numbers using a Single Variable? :-) If yes then show me the code!!! Regards Nirjhar
11
by: Elmo | last post by:
Hi all! I am not very proud to ask this but here is my problem: string code = "\'13\'" The string code will have to contain following info: '51','52','63','other'... to get certain info...
23
by: dkirkdrei | last post by:
I am having a bit of trouble trying to double up on slashes in a file path. What I am trying to do is very similar to the code below: <? $var =...
0
by: dhascuba | last post by:
The @name field can contain a single quote in it such as: Mike O'Grady. Since this is creating and SQL statement on the server side, it will not process the name if it has a single quote in it. Id'...
2
by: BobRoyAce | last post by:
I am using VB.NET and I have a variable that is defined as Nullable(Of Single) as follows: Dim fMyNullableSingle as Nullable(Of Single) Then, I have another variable as follows: Dim...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.