Passing text parameters including quotes in SQL Server

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]
   @cTableName
  ,@cCriteria
  ,@iRowsAffected OUTPUT
GO

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.

Help!
reticentKoalaAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
duplicate the single quotes:
DECLARE @iRowsAffected int
EXEC spDeleteRows_IdentifyTables 'Claim', 'DateClosed < ''01/01/2008''', @iRowsAffected OUTPUT 

Open in new window

0
 
Kamaraj SubramanianApplication Support AnalystCommented:
use two single quote ( instead of one )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.