Why do not we accept bank objects as parameters in a stored procedure?
Ex:
@COLUNA nvarchar(30),
@VARIAVEL nvarchar(50)
SELECT * FROM TBL_TESTE WHERE @COLUNA = @VARIAVEL
The only alternative would be dynamic queries?
Why do not we accept bank objects as parameters in a stored procedure?
Ex:
@COLUNA nvarchar(30),
@VARIAVEL nvarchar(50)
SELECT * FROM TBL_TESTE WHERE @COLUNA = @VARIAVEL
The only alternative would be dynamic queries?
SQL Server Does not concatenate commands only values, so you can pass values for a command to be mounted 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, please let me know
declare
@campo varchar(50),
@valor varchar(50),
@qry varchar(max)
set @campo = 'Inscricao';
set @valor = '123456';
set @qry = 'select * from tabela where ' + @inscricao + ' = ' + @valor;
Exec (@qry)