以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- INNER JOIN (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=55279) |
||||
-- 作者:bagabaga -- 发布时间:2014/8/13 16:55:00 -- INNER JOIN 这段代码搞了几天了,搞不定,特来请教 Dim Multi As String = e.Table.Current("Fk") Dim Values() As String Dim sql As String ="" Values = Multi.split("/") If e.Table.Current("Xh") <> "" \' MessageBox.Show(Values(2)) sql = "Select RcjBm as 人材机编码,Mc as 名称,Dw as 单位,Rcjhl As 含量,Rcjhj as 合计 FROM (SELECT Rcjid,Rcjhl,Rcjhj From {QdxrcjhlMx} where Fk = \'" & Values(2) & "\') as a INNER JOIN {RcjhzMx} as b ON b.RcjId = a.RcjId " Else \' MessageBox.Show(Values(3)) sql = "Select RcjBm as 人材机编码,Mc as 名称,Dw as 单位,Rcjhl As 含量,Rcjhj as 合计 FROM (SELECT Rcjid,Rcjhl,Rcjhj From {QdxdercjhlMx} where Fk = \'" & Values(3) & "\') as a INNER JOIN {RcjhzMx} as b ON b.RcjId = a.RcjId " End If If sql <> "" Dim b As New GroupTableBuilder("统计表1",sql) 此主题相关图片如下:捕获.png
b.Groups.AddDef("人材机编码") b.Groups.AddDef("名称") b.Groups.AddDef("单位") b.Groups.AddDef("含量") b.Totals.AddDef("合计") b.VerticalTotal = True \' b.Build() Dim dr As Table = Tables("清单_Table17") dr.DataSource = b.BuildDataSource() For Each cc As Col In dr.Cols If cc.Name = "名称" cc.Width =80 Else cc.Width =60 End If Next End If End If 1、先从当前表{Qdmx}中读取列Fk字符串 2、判断当前Row列(Xh)是不是为空,不为空,取From {QdxrcjhlMx},Select FK = 字符串(2), 3、为空From {QdxdercjhlMx} ,Select FK = 字符串(3) 4、 INNER JOIN {RcjhzMx} 读取Mc、RjcBM 结果如下图,问题是取出的结果不满足Select FK = 字符串(2)或Select FK = 字符串(3),多了别的内容,请教是什么原因,代码附上 |
||||
-- 作者:有点甜 -- 发布时间:2014/8/13 17:15:00 -- 呃,代码没有错,有可能是你逻辑有问题或者数据有问题。
比如 FK = 8,人材机id有如下 81 83 90 101 106 110 112 114,那么匹配【RcjhzMx】表的时候,就匹配了对应的数据,而你【RcjhzMx】有两个重复的Id 81、83、90等
所以数据是没有错的,但不知道你要取的是什么数据。 |
||||
-- 作者:bagabaga -- 发布时间:2014/8/13 19:29:00 -- 谢谢,{RcjhzMx}是有二个值,如果要对应条件Fk1=1, INNER JOIN {RcjhzMx} as b ON b.RcjId = a.RcjId 这一句该怎么写 |
||||
-- 作者:有点甜 -- 发布时间:2014/8/13 19:34:00 -- If e.Table.Current("Xh") <> "" \' MessageBox.Show(Values(2)) sql = "Select RcjBm as 人材机编码,Mc as 名称,Dw as 单位,Rcjhl As 含量,Rcjhj as 合计 FROM (SELECT Rcjid,Rcjhl,Rcjhj From {QdxrcjhlMx} where Fk = \'" & Values(2) & "\') as a INNER JOIN {RcjhzMx} as b ON b.RcjId = a.RcjId where fk1 = \'1\'" Else \' MessageBox.Show(Values(3)) sql = "Select RcjBm as 人材机编码,Mc as 名称,Dw as 单位,Rcjhl As 含量,Rcjhj as 合计 FROM (SELECT Rcjid,Rcjhl,Rcjhj From {QdxdercjhlMx} where Fk = \'" & Values(3) & "\') as a INNER JOIN {RcjhzMx} as b ON b.RcjId = a.RcjId where fk1 = \'1\'" End If |