[Last Call] Learn how to a build a cloud-first strategyRegister Now


Passing text parameters including quotes in SQL Server

Posted on 2012-08-20
Medium Priority
Last Modified: 2012-08-20
I'm sure this will be a straightforward one for someone to answer, but my brain is about to melt trying to get this to work.

I have a stored procedure that accepts 3 parameters:

DECLARE @cTableName varchar(50)
DECLARE @cCriteria nvarchar(1000)
DECLARE @iRowsAffected int

-- TODO: Set parameter values here.

EXECUTE [dbo].[spDeleteRows_IdentifyTables]
  ,@iRowsAffected OUTPUT

I want to pass it a string including a piece of text:
DECLARE @iRowsAffected int
EXEC spDeleteRows_IdentifyTables 'Claim', 'DateClosed < '01/01/2008'', @iRowsAffected OUTPUT

This generates a syntax error because I'm not escaping the quotes correctly.

Question by:reticentKoala
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 1400 total points
ID: 38312197
duplicate the single quotes:
DECLARE @iRowsAffected int
EXEC spDeleteRows_IdentifyTables 'Claim', 'DateClosed < ''01/01/2008''', @iRowsAffected OUTPUT 

Open in new window

LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 38312232
use two single quote ( instead of one )

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question