Use of Single Quotes for Stored Procedure Parameters in SQL Server


In SQL Server, single quotes are used to delimit string literals. When defining stored procedure parameters that are strings, it is important to use single quotes to delimit the parameter value.

Here is an example of a stored procedure that takes a string parameter:

CREATE PROCEDURE myProcedure
    @myStringParam VARCHAR(50)
AS
BEGIN
    -- Do something with @myStringParam
END

To call this stored procedure and pass in a string parameter, you would use single quotes to delimit the parameter value:

EXEC myProcedure 'my string parameter value'

If the parameter value itself contains single quotes, you can escape them by doubling them up:

EXEC myProcedure 'my ''quoted'' string parameter value'

Alternatively, you can use the QUOTED_IDENTIFIER setting to allow double quotes to be used instead of single quotes to delimit string literals. To do this, you would need to set QUOTED_IDENTIFIER to ON before creating the stored procedure:

SET QUOTED_IDENTIFIER ON

CREATE PROCEDURE myProcedure
    @myStringParam VARCHAR(50)
AS
BEGIN
    -- Do something with @myStringParam
END

Then, when calling the stored procedure, you can use double quotes to delimit the parameter value:

EXEC myProcedure "my string parameter value"


About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.