Question:
Why when we pass database objects as parameters in a stored procedure they are not accepted?
Ex:
@COLUNA nvarchar(30),
@VARIAVEL nvarchar(50)
SELECT * FROM TBL_TESTE WHERE @COLUNA = @VARIAVEL
Would the only alternative be dynamic queries?
Answer:
SQL Server doesn't concatenate commands to just values, so you can pass values so that a command is assembled and executed, Example:
@COLUNA nvarchar(30),
@VARIAVEL nvarchar(50)
declare @CMD varchar(4000)
set @CMD = 'SELECT * FROM TBL_TESTE WHERE '+@COLUNA+' = '+@VARIAVEL+''
exec sp_executeSQL @CMD
If you still have questions, let me know