Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Inserting single quotes in Query Analyzer
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

33 Posts

Posted - 12/11/2006 :  23:41:19  Show Profile  Reply with Quote
Hi guys,

I am working on a stored procedure which requires appending a single quote to a variable string, but SQL treats strings enclosed in single quotes. Can anyone teach me how to represent single quote to allow my procedure to insert single quotes?

I have tried the below:
1. SET @var = '''
2. SET @var = "'"
3. SET @var = convert(varchar,"'")

obviously 1 will not work, and 2 and 3 returns invalid column name '''.

Please help me out, thanks guys.

Posting Yak Master

137 Posts

Posted - 12/12/2006 :  00:04:34  Show Profile  Click to see gsgill76's MSN Messenger address  Send gsgill76 a Yahoo! Message  Reply with Quote
Try this

DECLARE @var varchar(10)
SET @var = 'GILL'''
PRINT @var

Rule of thumb is put TWO single quotes, if u need to put single quote in the string.
More Information: Read
from BOL.

Gurpreet S. Gill
Go to Top of Page

Starting Member

33 Posts

Posted - 12/12/2006 :  00:14:36  Show Profile  Reply with Quote
Thank you so much Gill :)
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 12/12/2006 :  05:59:20  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You need to double the single quote. Run this to know how it behavs

Select '','''','''''','''''''',''''''''''


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000