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
 General SQL Server Forums
 New to SQL Server Programming
 How to enter single quote character

Author  Topic 

venkath
Posting Yak Master

202 Posts

Posted - 2006-09-22 : 02:02:43
Hi all

How to enter single quote character in a sting column for eg: Channel's

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-09-22 : 02:04:55
escape it with another single quote

'Channel''s'



KH

Go to Top of Page

venkath
Posting Yak Master

202 Posts

Posted - 2006-09-22 : 02:07:11
Thanks
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2006-09-22 : 05:59:54
Another option is to use the ascii code for the single quote ie 39.

select 'Channel' + CHAR(39) + 's'


Duane.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-23 : 09:06:47
To know the behaviour of single quotes, run this

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

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-09-23 : 12:41:56
Evil!

Then there is this:

DECLARE @strSQL varchar(8000)
SELECT @strSQL = 'SELECT TOP 10 name FROM master.dbo.sysobjects WHERE type = ''U'''

SELECT @strSQL = '
SELECT *
FROM OPENQUERY(MyServer,
'''
+ REPLACE(@strSQL, '''', '''''')
+ '''
)'

PRINT @strSQL

EXEC (@strSQL)

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-24 : 20:47:22
Well. General rule may be
Between first and last single quotes, every double single quotes is converted to single single quote

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -