Could not create procedure Error: Must declare the scalar variable “@TableName”
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
add a comment |
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
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 picknvarchar(127)
as the type/size?sysname
, the actual data type used for such names is the same asnvarchar(128)
.
– Damien_The_Unbeliever
Nov 13 '18 at 8:50
add a comment |
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
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
sql-server variables stored-procedures
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 picknvarchar(127)
as the type/size?sysname
, the actual data type used for such names is the same asnvarchar(128)
.
– Damien_The_Unbeliever
Nov 13 '18 at 8:50
add a comment |
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 picknvarchar(127)
as the type/size?sysname
, the actual data type used for such names is the same asnvarchar(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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 13 '18 at 8:37
Serkan EkşioğluSerkan Ekşioğlu
1309
1309
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 asnvarchar(128)
.– Damien_The_Unbeliever
Nov 13 '18 at 8:50