嵌套选择不排除数据

时间:2017-12-19 16:37:09

标签: sql sql-server select nested

我正在构建这个select语句,并且达到了我的条件不起作用的程度。这是代码:

select * 
from (
select ref,usr1,design,forref,replace(stock,'.',',')as stock 
from st
where inactivo like '0' 
and usr1 not in ('Serv','Reciclagem','portes','pbl','ctb','') 
and forref not in ('','0')
     ) total
where ref not in ('10159%','13159%')
order by usr1

问题是,当我写行以排除ref表上的某些值时,没有任何反应。

where ref not in ('10159%','13159%')

哪里错了?

1 个答案:

答案 0 :(得分:0)

尝试使用

WHERE LEFT(ref, 5) NOT IN ('10159','13159')

HTH!

感谢。