Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
条件中的SQL Server条件_Sql_Sql Server - Fatal编程技术网

条件中的SQL Server条件

条件中的SQL Server条件,sql,sql-server,Sql,Sql Server,我想说: “如果前两个字母不是10,且以10开头的字母仅排除2018年以后的字母” where (left(c.DealCode, 2) <> '10' and estyear > 2018) 不起作用。。我错过了什么 你说: where left(c.DealCode, 2) <> '10' or (left(c.DealCode, 2) = '10' and estyear > 2018) '其中前两个字母不是10,对于那些确实以10开头的字母

我想说:

“如果前两个字母不是10,且以10开头的字母仅排除2018年以后的字母”

where (left(c.DealCode, 2) <> '10'
    and estyear > 2018)
不起作用。。我错过了什么

你说:

where left(c.DealCode, 2) <> '10' or (left(c.DealCode, 2) = '10' and estyear > 2018)
'其中前两个字母不是10,对于那些确实以10开头的字母 只有10个不包括2018年以后的'

但是你应该说:

'其中前两个字母不是10,或者是那些以10开头的字母 只有10个不包括2018年以后的'

所以你必须在你的陈述中用OR代替AND。 还有这样一句话:

(a doesn't start with 10) or ((a starts with 10) and (estyear > 2018))
相当于

(a doesn't start with 10) or (estyear > 2018)
所以你的情况应该是:

where c.DealCode not like '10%' or estyear > 2018
但不确定是否

不包括2018年以后的


必须是estyear>2018或estyear<2018

编辑问题,添加一些样本数据,期望的结果会有所帮助。
where c.DealCode not like '10%' or estyear > 2018