Skip to content
Advertisement

How to fix that procedure in sql

I created procedure which count not null rows in the column, but query throws errors: @tableName is not declared and invalid object name tempTable. I don’t know why code throws that errors, because all variables are declared.

Also when I make that program in another way, that code throw Msg 1087, Level 15, State 2, Line 11 error.

Is it a way to fix that error?

Advertisement

Answer

Obviously, your code is subject to SQL injection attacks — as the comments on the question have explained.

But your issue is the scoping rules around your table variable. You can fix that by using:

I don’t think there is any way around the SQL injection vulnerabilities for the logic you have suggested. However, your code is so non-sensical that I doubt that it is really representative of your actual code.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement