Could not create procedure Error: Must declare the scalar variable “@TableName”












1















CREATE PROCEDURE [dbo].[sp_DropMasks]
@TableName nvarchar(127)='',
@FieldName nvarchar(127)='',
@MaskFunction nvarchar(127)=''
AS
BEGIN
declare @ATableName nvarchar(127)=''
declare @AFieldName nvarchar(127)=''
declare @AMaskFunction nvarchar(127)=''
declare @SqlStr nvarchar(max)=''
DECLARE crs CURSOR Read_Only Fast_Forward FOR
SELECT TOP 100 PERCENT
TableName=tbl.name,
ColumnName=c.name,
c.masking_function
FROM
sys.masked_columns AS c inner join
sys.tables AS tbl ON c.object_id = tbl.object_id
WHERE
is_masked=1 and
tbl.name like '%'+@TableName+'%' and
c.name like '%'+@FieldName+'%' and
c.masking_function like '%'+@MaskFunction+'%'
Open crs
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
WHILE @@FETCH_STATUS = 0
BEGIN
set @SqlStr = @SqlStr +
' ALTER TABLE ' + @ATableName +
' ALTER COLUMN ' + @AFieldName +
' DROP MASKED '
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
END
CLOSE crs
DEALLOCATE crs
if @SqlStr <> ''
exec(@SqlStr)
END;


I cannot see the invalid syntax or the missing declaration.



The error is;




Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.











share|improve this question

























  • What is the SQL version you are using?

    – Thilina Nakkawita
    Nov 13 '18 at 7:55











  • version 14.0.3038.14

    – Serkan Ekşioğlu
    Nov 13 '18 at 7:56











  • try separating the procedure code with go

    – Sanal Sunny
    Nov 13 '18 at 8:35











  • If your parameters are intended to be table/column/function names, why on earth would you pick nvarchar(127) as the type/size? sysname, the actual data type used for such names is the same as nvarchar(128).

    – Damien_The_Unbeliever
    Nov 13 '18 at 8:50
















1















CREATE PROCEDURE [dbo].[sp_DropMasks]
@TableName nvarchar(127)='',
@FieldName nvarchar(127)='',
@MaskFunction nvarchar(127)=''
AS
BEGIN
declare @ATableName nvarchar(127)=''
declare @AFieldName nvarchar(127)=''
declare @AMaskFunction nvarchar(127)=''
declare @SqlStr nvarchar(max)=''
DECLARE crs CURSOR Read_Only Fast_Forward FOR
SELECT TOP 100 PERCENT
TableName=tbl.name,
ColumnName=c.name,
c.masking_function
FROM
sys.masked_columns AS c inner join
sys.tables AS tbl ON c.object_id = tbl.object_id
WHERE
is_masked=1 and
tbl.name like '%'+@TableName+'%' and
c.name like '%'+@FieldName+'%' and
c.masking_function like '%'+@MaskFunction+'%'
Open crs
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
WHILE @@FETCH_STATUS = 0
BEGIN
set @SqlStr = @SqlStr +
' ALTER TABLE ' + @ATableName +
' ALTER COLUMN ' + @AFieldName +
' DROP MASKED '
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
END
CLOSE crs
DEALLOCATE crs
if @SqlStr <> ''
exec(@SqlStr)
END;


I cannot see the invalid syntax or the missing declaration.



The error is;




Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.











share|improve this question

























  • What is the SQL version you are using?

    – Thilina Nakkawita
    Nov 13 '18 at 7:55











  • version 14.0.3038.14

    – Serkan Ekşioğlu
    Nov 13 '18 at 7:56











  • try separating the procedure code with go

    – Sanal Sunny
    Nov 13 '18 at 8:35











  • If your parameters are intended to be table/column/function names, why on earth would you pick nvarchar(127) as the type/size? sysname, the actual data type used for such names is the same as nvarchar(128).

    – Damien_The_Unbeliever
    Nov 13 '18 at 8:50














1












1








1


1






CREATE PROCEDURE [dbo].[sp_DropMasks]
@TableName nvarchar(127)='',
@FieldName nvarchar(127)='',
@MaskFunction nvarchar(127)=''
AS
BEGIN
declare @ATableName nvarchar(127)=''
declare @AFieldName nvarchar(127)=''
declare @AMaskFunction nvarchar(127)=''
declare @SqlStr nvarchar(max)=''
DECLARE crs CURSOR Read_Only Fast_Forward FOR
SELECT TOP 100 PERCENT
TableName=tbl.name,
ColumnName=c.name,
c.masking_function
FROM
sys.masked_columns AS c inner join
sys.tables AS tbl ON c.object_id = tbl.object_id
WHERE
is_masked=1 and
tbl.name like '%'+@TableName+'%' and
c.name like '%'+@FieldName+'%' and
c.masking_function like '%'+@MaskFunction+'%'
Open crs
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
WHILE @@FETCH_STATUS = 0
BEGIN
set @SqlStr = @SqlStr +
' ALTER TABLE ' + @ATableName +
' ALTER COLUMN ' + @AFieldName +
' DROP MASKED '
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
END
CLOSE crs
DEALLOCATE crs
if @SqlStr <> ''
exec(@SqlStr)
END;


I cannot see the invalid syntax or the missing declaration.



The error is;




Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.











share|improve this question
















CREATE PROCEDURE [dbo].[sp_DropMasks]
@TableName nvarchar(127)='',
@FieldName nvarchar(127)='',
@MaskFunction nvarchar(127)=''
AS
BEGIN
declare @ATableName nvarchar(127)=''
declare @AFieldName nvarchar(127)=''
declare @AMaskFunction nvarchar(127)=''
declare @SqlStr nvarchar(max)=''
DECLARE crs CURSOR Read_Only Fast_Forward FOR
SELECT TOP 100 PERCENT
TableName=tbl.name,
ColumnName=c.name,
c.masking_function
FROM
sys.masked_columns AS c inner join
sys.tables AS tbl ON c.object_id = tbl.object_id
WHERE
is_masked=1 and
tbl.name like '%'+@TableName+'%' and
c.name like '%'+@FieldName+'%' and
c.masking_function like '%'+@MaskFunction+'%'
Open crs
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
WHILE @@FETCH_STATUS = 0
BEGIN
set @SqlStr = @SqlStr +
' ALTER TABLE ' + @ATableName +
' ALTER COLUMN ' + @AFieldName +
' DROP MASKED '
Fetch Next From crs INTO @ATableName,@AFieldName,@AMaskFunction
END
CLOSE crs
DEALLOCATE crs
if @SqlStr <> ''
exec(@SqlStr)
END;


I cannot see the invalid syntax or the missing declaration.



The error is;




Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 156, Level 15, State 1, Line 28 Incorrect syntax near the keyword
'PROCEDURE'.



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 137, Level 15, State 2, Line 45 Must declare the scalar variable
"@TableName".



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.



Msg 8180, Level 16, State 1, Procedure
sp_describe_parameter_encryption, Line 1 [Batch Start Line 27]
Statement(s) could not be prepared.








sql-server variables stored-procedures






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 9:18









WhatsThePoint

2,17662136




2,17662136










asked Nov 13 '18 at 7:53









Serkan EkşioğluSerkan Ekşioğlu

1309




1309













  • What is the SQL version you are using?

    – Thilina Nakkawita
    Nov 13 '18 at 7:55











  • version 14.0.3038.14

    – Serkan Ekşioğlu
    Nov 13 '18 at 7:56











  • try separating the procedure code with go

    – Sanal Sunny
    Nov 13 '18 at 8:35











  • If your parameters are intended to be table/column/function names, why on earth would you pick nvarchar(127) as the type/size? sysname, the actual data type used for such names is the same as nvarchar(128).

    – Damien_The_Unbeliever
    Nov 13 '18 at 8:50



















  • What is the SQL version you are using?

    – Thilina Nakkawita
    Nov 13 '18 at 7:55











  • version 14.0.3038.14

    – Serkan Ekşioğlu
    Nov 13 '18 at 7:56











  • try separating the procedure code with go

    – Sanal Sunny
    Nov 13 '18 at 8:35











  • If your parameters are intended to be table/column/function names, why on earth would you pick nvarchar(127) as the type/size? sysname, the actual data type used for such names is the same as nvarchar(128).

    – Damien_The_Unbeliever
    Nov 13 '18 at 8:50

















What is the SQL version you are using?

– Thilina Nakkawita
Nov 13 '18 at 7:55





What is the SQL version you are using?

– Thilina Nakkawita
Nov 13 '18 at 7:55













version 14.0.3038.14

– Serkan Ekşioğlu
Nov 13 '18 at 7:56





version 14.0.3038.14

– Serkan Ekşioğlu
Nov 13 '18 at 7:56













try separating the procedure code with go

– Sanal Sunny
Nov 13 '18 at 8:35





try separating the procedure code with go

– Sanal Sunny
Nov 13 '18 at 8:35













If your parameters are intended to be table/column/function names, why on earth would you pick nvarchar(127) as the type/size? sysname, the actual data type used for such names is the same as nvarchar(128).

– Damien_The_Unbeliever
Nov 13 '18 at 8:50





If your parameters are intended to be table/column/function names, why on earth would you pick nvarchar(127) as the type/size? sysname, the actual data type used for such names is the same as nvarchar(128).

– Damien_The_Unbeliever
Nov 13 '18 at 8:50












1 Answer
1






active

oldest

votes


















0














i forgot to switch always encrypted off when i connect.



thanks to



Cannot add a stored procedure to database due to encryption message



now works just fine.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276229%2fcould-not-create-procedure-error-must-declare-the-scalar-variable-tablename%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    i forgot to switch always encrypted off when i connect.



    thanks to



    Cannot add a stored procedure to database due to encryption message



    now works just fine.






    share|improve this answer




























      0














      i forgot to switch always encrypted off when i connect.



      thanks to



      Cannot add a stored procedure to database due to encryption message



      now works just fine.






      share|improve this answer


























        0












        0








        0







        i forgot to switch always encrypted off when i connect.



        thanks to



        Cannot add a stored procedure to database due to encryption message



        now works just fine.






        share|improve this answer













        i forgot to switch always encrypted off when i connect.



        thanks to



        Cannot add a stored procedure to database due to encryption message



        now works just fine.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 8:37









        Serkan EkşioğluSerkan Ekşioğlu

        1309




        1309






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276229%2fcould-not-create-procedure-error-must-declare-the-scalar-variable-tablename%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation