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

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Inserting single quotes in Query Analyzer

Author  Topic 

suchiate
Starting Member

33 Posts

Posted - 2006-12-11 : 23:41:19
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

137 Posts

Posted - 2006-12-12 : 00:04:34
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 - 2006-12-12 : 00:14:36
Thank you so much Gill :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-12 : 05:59:20
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
   

- Advertisement -