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

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

suchiate
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.

gsgill76
Posting Yak Master

India
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
SET QUOTED_IDENTIFIER (Transact-SQL)
from BOL.

Gurpreet S. Gill
Go to Top of Page

suchiate
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

madhivanan
Premature Yak Congratulator

India
22769 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 '','''','''''','''''''',''''''''''

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000