SQL Server에서이 사례 문을 어떻게 사용할 수 있습니까?WHERE 절에 추가 할 CASE 문?
declare @isnot tinyint
select @isnot = 1
select top 100 *
from Employee
where EmployeeID > 1
and case
when @isnot = 1
then (EmployeeName = 'Brian')
else (EmployeeName = 'Anie')
end
이 쿼리는 어떻게됩니까?
declare @isnot tinyint
select @isnot = 1 -- option : 0 and 1
select top 100 *
from Employee
where EmployeeID > 1
case
when @isnot = 1
then (and EmployeeName = 'Brian')
else '' -- blank
end
하위 쿼리 등을 사용하고 싶지 않습니다. 당신이 값 진 수표를 사용하고 있기 때문에
끝 부분에'END'가 누락되었습니다 ...'CASE' 문을'END'로 끝내야합니다. –
@ Aominè 내 where 문에 대소 문자를 추가하여 자동으로 추가합니다. Employee = ' Bran 'or Employee ='Anie ' – Richard
WHERE 절과 ON 절에서 대소 문자를 구분하는 대신'AND' /'OR '를 사용하는 것이 일반적으로 훨씬 낫습니다. – jarlh