Please start any new threads on our new site at http://forums.sqlteam.com. 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!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query Problem
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sanjay5219
Posting Yak Master

240 Posts

Posted - 07/16/2013 :  10:01:21  Show Profile  Reply with Quote
Hi All,

I have this value in table T1.
test5''4_test_X43_9_2_27

When I am running below query nothing is coming.

Select * from T1 Where Id='test5''4_test_X43_9_2_27'

Please suggest

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/16/2013 :  10:08:35  Show Profile  Reply with Quote
quote:
Originally posted by sanjay5219

Hi All,

I have this value in table T1.
test5''4_test_X43_9_2_27

When I am running below query nothing is coming.

Select * from T1 Where Id='test5''4_test_X43_9_2_27'

Please suggest


Escape each single quote that is part of the data with another single quote. So in your example, you should have four single quotes between the 5 and the 4.
Select * from T1 Where Id='test5''''4_test_X43_9_2_27'
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 07/16/2013 :  10:11:33  Show Profile  Reply with Quote
Can I get a function for this so that I can use every where in applicaiton . Please suggest
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/16/2013 :  10:27:01  Show Profile  Reply with Quote
quote:
Originally posted by sanjay5219

Can I get a function for this so that I can use every where in applicaiton . Please suggest

Not sure what you mean by function for this. When you want to use a string literal, you have to escape each single quote with another single quote. That applies only to string literals. So, for example, if you were to put the value into a variable, then you can use it everywhere without worrying about escaping like shown below.
DECLARE @searchTerm VARCHAR(32) = 'test5''''4_test_X43_9_2_27'
Select * from T1 Where Id=@searchTerm

Or, if you were sending in the searchTerm from client code such as a C# program in a variable, then again, you wouldn't have to worry about the escape characters.
Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 07/16/2013 :  10:38:59  Show Profile  Reply with Quote
Actually there are places where I can find 1 single quote some time '' and some time ''' single quotes. I thought if I will create function it will be easy for me
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.41 seconds. Powered By: Snitz Forums 2000