I have a dynamic sql that works fine when the name of the columns exists, how can I make it not send error if the column does not exist
DECLARE @codigo NVARCHAR(200)
DECLARE @column NVARCHAR(200)
SET @codigo = '110201'
SET @column = '[1]'
DECLARE @sqlQuery NVARCHAR(MAX);
SET @sqlQuery = N'SELECT '+ @column + ' FROM Codigo_Obra_Tipo_Actividad WHERE ' + @column + ' = ''' + @codigo + ''''
EXEC (@sqlQuery)