以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  内部数据源关联外部数据源问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=81230)

--  作者:happy_gile
--  发布时间:2016/2/22 11:26:00
--  内部数据源关联外部数据源问题
同一数据源sel ect * from 表A where 表A.金额 not in (sel ect 金额 from 表B where 表A.编码=表B.编码)
若两个表分别为不同数据源
内部数据源中有一个表A,表中有编码、金额两列
外部数据源中有一个表B,表中也有编码、金额两列
想查询表B中编码=表A中编码 且 表B中金额<>表A中金额怎么写?

[此贴子已经被作者于2016/2/22 11:29:04编辑过]

--  作者:大红袍
--  发布时间:2016/2/22 12:23:00
--  

不同的数据源,不能直接写sql语句。

 

你要用代码处理,如

 

Dim idx As String = "-1,"
For Each dr As DataRow In DataTables("表A").DataRows
    If DataTables("表B").find("编码 = \'" & dr("编码") & "\' and 金额 = \'" & dr("金额") & "\'") Is Nothing Then
        idx &= dr("_Identify") & ","
    End If
Next
Tables("表A").Filter = "_Identify in (" & idx.trim(",") & ")"


--  作者:happy_gile
--  发布时间:2016/2/22 14:10:00
--  

[此贴子已经被作者于2016/2/22 14:15:46编辑过]

--  作者:happy_gile
--  发布时间:2016/2/22 14:16:00
--  
你好老师,我是要查出来表B中的所有编码=表A中编码 并且 金额不等于表A中该编码所对应的金额的数据
例如:
表A                       表B
数量    金额          数量   金额
10      100          10     100
10      101          10     101
20    200        10   102
20      201          10     103
                         20     200
                         20     201
                         20     202
查询结果
编码   金额
10     102
10     103
20     202

--  作者:大红袍
--  发布时间:2016/2/22 14:28:00
--  

 

[此贴子已经被作者于2016/2/22 14:28:28编辑过]

--  作者:大红袍
--  发布时间:2016/2/22 14:32:00
--  
Dim idx As String = "-1,"
For Each dr As DataRow In DataTables("表B").DataRows
    If DataTables("表A").find("编码 = \'" & dr("编码") & "\'") IsNot Nothing Then
        If DataTables("表B").find("编码 = \'" & dr("编码") & "\' and 金额 <> \'" & dr("金额") & "\'") Is Nothing Then
            idx &= dr("_Identify") & ","
        End If
    End If
Next
Tables("表B").Filter = "_Identify in (" & idx.trim(",") & ")"