Pregunta sobre case en un Where

25/10/2004 - 22:46 por German | Informe spam
Quisiera saber si hay alguna forma de hacer lo siguiente

Declare @Valor int, @Otro varchar(20)

Select *
from tabla_mia
weher
Case @Valor
when 1 then interno = cast(@Otro as int)
when 2 then nrochasis = @Otro
end

lo que quiero es que la condicion sea variable segun el
valor que trae @Valor
Desde ya muchas gracias
 

Leer las respuestas

#1 Isaias
25/10/2004 - 23:21 | Informe spam
"Mr. Bond", creo que seria asi:

DECLARE @SQLString NVARCHAR(100), @MyValor smallint
SET @MyValor = 1
SET @SQLString = N'Select *
from tabla_mia
where '+ CASE WHEN @VALOR 1 THEN 'interno = '+ @Otro ELSE 'nrochasis =
'+@Otro END
EXECUTE sp_executesql @SQLString

Preguntas similares