Ver originalDECLARE @query VARCHAR(MAX) SET @query='select * from tabla' IF @var>=1 SET @query=@query + 'where id=' + @var EXEC Sp_sqlExec @query