vedamurthy
vedamurthy

Reputation: 45

Create Stored Procedure for VIEW

I am trying to create a stored procedure for the view as shown below, but it's throwing an error

Incorrect syntax near 'N'

If I removed the quote, then it works. Please suggest me how to put value N in quotes.

ALTER PROCEDURE [dbo].[SP_VIEW] 
AS
BEGIN
    EXECUTE('
        CREATE VIEW [dbo].[SP_VIEW]
        AS
            SELECT * 
            FROM [dbo].[ACTIVITY] 
            WHERE IND = 'N'')
END

Upvotes: 1

Views: 86

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175646

SQL Server does not supports here-string so you have to double every ':

ALTER PROCEDURE  [dbo].[SP_VIEW] 
AS
BEGIN
    EXECUTE('
CREATE VIEW [dbo].[SP_VIEW]
AS
SELECT * FROM [dbo].[ACTIVITY] 
where IND=''N''
');
END

Azure Feedback: Add support for here-strings i T-SQL

Upvotes: 1

Related Questions