2010-07-07 2 views

답변

8

당신이 할 수있는 동적 SQL 사용 :

declare @query varchar(max) 
set @query = 'select * from MyTable where first_column = ''1'' ' + 
    @operator + ' second_column = ''2''' 
exec (@query) 

때때로, 문 로직이 같은 충분하다 :

select * 
from MyTable 
where (operator = 'AND' and first_column = '1' and second_column = '2') 
     or (operator = 'OR' and (first_column = '1' or second_column = '2')) 
당신이 정말로에 의해 T-SQL에서이 [동적 검색 조건을 읽을 필요가
관련 문제