Foxtable(狐表)用户栏目专家坐堂 → [求助] SQL语句求助


  共有2076人关注过本帖树形打印复制链接

主题:[求助] SQL语句求助

帅哥哟,离线,有人找我吗?
2900819580
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1347 积分:9817 威望:0 精华:0 注册:2015/6/30 8:46:00
[求助] SQL语句求助  发帖心情 Post By:2018/7/3 20:38:00 [只看该作者]

Dim tb As Table = Tables(e.Form.Name & "_Table1")
tb.Fill("sele ct * fr om {物料表} where ( 单位 Is null Or 默认仓库名称 Is null )", "ksg", False)
tb.SetColVisibleWidth("代码|154|名称|204|规格型号|135|单位|36|备注|262|类别|130|类型|59|默认仓库名称|98")
For Each r As Row In tb.Rows
   
    Dim cmd As new SQLCommand
   
    cmd.C   
    cmd.CommandText = "select * fr om {t_ICItemCore} where FNumber = '" & r("代码") & "'"
    Dim dt As DataTable = cmd.ExecuteReader
   
    If dt.DataRows.Count > 0 Then
        Dim dr As DataRow = dt.DataRows(0)
       
        cmd.CommandText = "select * fr om {t_ICItemBase} where FItemID = '" & dr("FItemID") & "'"
        Dim dt1 As DataTable = cmd.Ex ecuteReader
        Dim dr1 As DataRow = dt1.DataRows(0)
       
        If dr1("FDefaultLoc") <> "0" Then
            cmd.CommandText = "select * fr om {t_Stock} where FItemID = '" & dr1("FDefaultLoc") & "'"
            Dim dt2 As DataTable = cmd.ExecuteReader
            Dim dr2 As DataRow = dt2.DataRows(0)
            R("默认仓库名称") = dr2("FName")
        End If
       
        cmd.CommandText = "select * fr om {t_MeasureUnit} where FItemID = '" & dr1("FUnitID") & "'"
        Dim dt3 As DataTable = cmd.ExecuteReader
        Dim dr3 As DataRow = dt3.DataRows(0)
        R("单位") = dr3("FName")
       
        cmd.CommandText = "select * fro m {t_ICItemMaterial} where FItemID = '" & dr("FItemID") & "'"
        Dim dt4 As DataTable = cmd.ExecuteReader
        Dim dr4 As DataRow = dt4.DataRows(0)
      
        R("备注") = dr4("Fnote")
    Else
        R("单位") = "无用"
        R("默认仓库名称") = "无用"
    End If
Next
tb.DataTable.Save
MessageBox.Show("物料更新完成")

 

 

以上代码 能不能用SQL语句直接查找出来。

[此贴子已经被作者于2018/7/3 20:38:59编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110592 积分:562856 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2018/7/3 21:41:00 [只看该作者]

试试:

update 物料表 set 单位='无用',默认仓库名称='无用' from 物料表 where (单位 Is null Or 默认仓库名称 Is null) and not exists( select FNumber from t_ICItemCore where t_ICItemCore.FNumber = 物料表.代码)

update 物料表 set 默认仓库名称= c.FName from 物料表  As w Inner join t_ICItemCore As a on w.代码 = a.FNumber Inner join t_ICItemBase As b on a.FItemID = b.FItemID Inner join t_Stock As c on b.FDefaultLoc = c.FItemID where (w.单位 Is null Or w.默认仓库名称 Is null) and b.FDefaultLoc <> 0

还原一个测试库测试

 回到顶部