简体   繁体   English

Datagridview - 条件中的条件

[英]Datagridview - condition within condition

I think I'll explain this best with an image.我想我会用一张图片来最好地解释这一点。

在此处输入图片说明

I am using this line of code for datagridview above :我在上面的 datagridview 中使用这行代码:

        Dim SQLString As String = "SELECT NALOG, KONTO, DATPRO, BRDOK, OPIS, DUGUJE, POTRAZUJE FROM PROMGL WHERE NALOG LIKE '%U-%' AND DATPRO between #1/1/2014# and #12/31/2014#"

What I would like to do is only to take NALOG U-0004 and U-0005 in datagridview because they have "2702" in KONTO, since NALOG U-0001, U-0002 and U-0003 don't have "2702" I would like for them to be ignored.我想做的只是在 datagridview 中使用 NALOG U-0004 和 U-0005,因为它们在 KONTO 中有“2702”,因为 NALOG U-0001、U-0002 和 U-0003 没有“2702”我希望他们被忽略。

If I add WHERE KONTO LIKE %2702% I'll get only 2702 items in datagridview and other parts of NALOG that contains 2702 will be ignored and I would like to populate datagridview with complete NALOG if in KONTO is item 2702.如果我添加WHERE KONTO LIKE %2702%我只会在 datagridview 中得到 2702 个项目,而包含 2702 的 NALOG 的其他部分将被忽略,如果 KONTO 中的项目为 2702,我想用完整的 NALOG 填充 datagridview。

Is is possible to insert that condition within this condition WHERE NALOG LIKE '%U-%'是否可以在此条件中插入该条件WHERE NALOG LIKE '%U-%'

You can use a subquery to do that.您可以使用子查询来做到这一点。

SELECT * From yourTable WHERE Nalog IN 
  (SELECT Nalog FROM yourTable 
  WHERE NALOG LIKE '%U-%' 
  AND DATPRO between #1/1/2014# and #12/31/2014# 
  AND KONTO LIKE '%2702%')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM