SQL Server 2008:与Or一起使用的条款

时间:2016-04-13 16:50:46

标签: sql-server-2008

我有WHERE条款:

Where Year(CreateDate) >= '2016'
  and b.colors1 In ('Yellow','Red')
  Or  b.colors2 In ('Yellow','Red')
  Or  b.colors3 In ('Yellow','Red') 

我只想返回CreateDate >= 2016,但由于Or声明,我得到的数据超出了'2016'。我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:3)

试试这个,年份不是字符串

Where Year(CreateDate) >= 2016
and (b.colors1 In ('Yellow','Red')
     Or  b.colors2 In ('Yellow','Red')
     Or  b.colors3 In ('Yellow','Red') )