sql不用拼接语句实现动态查询条件
DECLARE @oFrom INT SET @oFrom = 2 SELECT * FROM baseinfo WHERE 1 = 1 AND ( (@oFrom = 0 and Type = 'OrderFrom' ) or ( @oFrom = 1 and Type = 'BillStatus' ) or ( @oFrom = 2 and Type = 'Breakfast') )
or的条件可自由添加,尤其适用互斥条件的查询。
DECLARE @oFrom INT SET @oFrom = 2 SELECT * FROM baseinfo WHERE 1 = 1 AND ( (@oFrom = 0 and Type = 'OrderFrom' ) or ( @oFrom = 1 and Type = 'BillStatus' ) or ( @oFrom = 2 and Type = 'Breakfast') )
or的条件可自由添加,尤其适用互斥条件的查询。