apostrophe in parameterised SP call trouble

S

spacehopper_man

hi -

I am having "apostrophe in sql" problems ;)

I am executing a stored procedure on SQL Server - and passing in a
string parameter.

the string has a single apostrophe in it.

the call is failing with an "Incorrect syntax" message.

when I profile SQL Server I see that it is being passed a command that
looks like this:

exec
up_myproc @iUserId = 1, @iCustomerId = 1,
@vcCustomerUser = 'oliver.o''(e-mail address removed)',
@dtStartDate = 'Jan 12 2005 5:41:18:370PM' ........

note that the apostrophe has now been doubled (presumably by the
framework) - and this statement now rejected by SQL Server.

so it seems that something (the framework somewhere) is attempting to
escape my query, but is doing so in such a way as to cause broken SQL
exec statements.
Any ideas what to do?
Anyone seen this before?

ta,
Oli.
 
K

Kevin Spencer

There's an echo in here!

A single quote (apostrophe) is a string delimiter in SQL. To escape it,
double it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top