What a good day, I have a question with SQL Server, how can I use a variable to choose if I want to add the not like or if I do not want to add it, I have this code but it does not work, it puts an error in the temporary table:
DECLARE @option CHAR(1)
DECLARE @sql_statement VARCHAR(MAX) = ''
SET @sql_statement = 'SELECT Numero,
Revision,
Nombre
INTO #REV
FROM dbo.sp_prueba'
IF @option = 'Y'
BEGIN
SET @sql_statement += 'WHERE Revision NOT LIKE ''XL%Dem''
AND Numero > 2'
END
ELSE
BEGIN
SET @sql_statement += 'WHERE Numero > 2'
END
EXEC(@sql_statement)