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.
Author |
Topic |
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2013-07-16 : 10:01:21
|
Hi All,I have this value in table T1. test5''4_test_X43_9_2_27When I am running below query nothing is coming.Select * from T1 Where Id='test5''4_test_X43_9_2_27'Please suggest |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-07-16 : 10:08:35
|
quote: Originally posted by sanjay5219 Hi All,I have this value in table T1. test5''4_test_X43_9_2_27When 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' |
|
|
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2013-07-16 : 10:11:33
|
Can I get a function for this so that I can use every where in applicaiton . Please suggest |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-07-16 : 10:27:01
|
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. |
|
|
sanjay5219
Posting Yak Master
240 Posts |
Posted - 2013-07-16 : 10:38:59
|
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 |
|
|
|
|
|