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
 Stray ' and Stroed Procedures

Author  Topic 

thedryden
Starting Member

23 Posts

Posted - 2008-04-18 : 11:21:02
Is there a way to deal with stray ' in strings, such as: 'SQL Team's', in stored procedures inputs without using variables. Normally I'd correct this by putting + char(39) + ' after that stray apostrophe but when I do that within a stored procedure it spits back an error about the + sign.

Can anyone help?

Just to be clear, the problem I’m dealing with is like the following:

EXEC Database.dbo.StoredProcedure 'SQL Team's'

And I’ve the following as a solution, but it returns “Incorrect syntax near '+'.”:

EXEC Database.dbo.StoredProcedure 'SQL Team' + char(39) + 's'

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-04-18 : 11:33:05
You can escape single quotes by doubling them up. i.e.:


'SQL Team''s'


Note that there are two single quote characters in a row, not a single double-quote character.

Be sure that if you have a client application calling stored procedures that you are using parameters and not putting input or data directly into a SQL statement via delimiting and concatenation.




- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

thedryden
Starting Member

23 Posts

Posted - 2008-04-18 : 11:38:51
But would that not return a string that had its original meaning changed? Is there no way to do it without changing the original meaning?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-04-18 : 12:33:43
I'm not sure what you are asking. Where are these strings coming from? Where is this SQL being executed? How about a complete example?

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-19 : 03:08:03
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx

Madhivanan

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

- Advertisement -