Foxtable(狐表)用户栏目专家坐堂 → 关于SQL查询问题


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

主题:关于SQL查询问题

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
关于SQL查询问题  发帖心情 Post By:2018/3/26 16:23:00 [显示全部帖子]

S elect t1.[项目编号],t1.[客户名称],t1.[物料代码],t1.[物料名称],t1.[规格型号],t1.[客户对应物料代码],
t1.[客户对应物料名称],t1.[实发数量],t1.[批号],t2.[FJianYanShuiPing],t2.[FAQLC],t2.[FAQLDF],t2.[FAQLUT],
t2.[FAQLIR],t2.[FAQLWaiGuan],t2.[FAQLYaMinDianYa],t2.[FAQLLouDianLiu],t2.[FAQLXianXingXiShu],
t2.[FAQLChongJiDianLiu],t2.[FCeDianYa],t2.[FCePinLv],t2.[FCeDianRongLiangC],t2.[FCeSunHaoDF],
t2.[FCeNaiDianYaUT],t2.[FJueYuanDianZu],t2.[FCSL],t2.[FCUSL],t2.[FCLSL],t2.[FDFSL],t2.[FDFUSL],
t2.[FDFLSL],t2.[FD],t2.[FT],t2.[FF],t2.[FD_d],t2.[FL],t2.[FWenDu],t2.[FShiDu],t2.[FYaMinWaiGuan],
t2.[FYaMinDianZuChiCun],t2.[FYaMinDianYa],t2.[FLouDianLiu],t2.[FXianXingXiShu],t2.[FZuiDaChongJiDianLiu],
t2.[FJingDianRongLiang],t2.[FSunHaoQieJiao],t2.[FHuiLuDianYa],t2.[FLangYongDianYa],t2.[FNaiDianYa],
t2.[FJueYuanDianZu_1],t2.[FZuRan],t2.[FKeHanXing],t2.[FLaShengQiangDu],t2.[FWanQuQiangDu],
t2.[FCeYaMinWaiGuan],t2.[FCeYaMinDianZuChiCun],t2.[FCeYaMinDianYa],t2.[FCeLouDianLiu],
t2.[FCeXianXingXiShu],t2.[FCeZuiDaChongJiDianLiu],t2.[FCeJingDianRongLiang],t2.[FCeSunHaoZhengQieJiao],
t2.[FCeHuiLuDianYa],t2.[FCeLangYongDianLiu],t2.[FCeNaiDianYa],t2.[FCeJueYuanDianZu],t2.[FCeZuRan],
t2.[FCeKeHanXing],t2.[FCeLaShengQiangDu],t2.[FCeWanQuQiangDu],t2.[FCeShiBaoGao],
t2.[客户料号] from 项目测试数据看板  As t1
INNER JOIN 报告指标项次 As t2 ON t1.[客户对应物料代码]=t2.[客户料号]
where 项目编号= '13'
这段在数据库执行是可以的
——————————————————————————
Dim sql2 As String ="S elect t1.[项目编号],t1.[客户名称],t1.[物料代码],t1.[物料名称],t1.[规格型号],t1.[客户对应物料代码]," & _
"t1.[客户对应物料名称],t1.[实发数量],t1.[批号],t2.[FJianYanShuiPing],t2.[FAQLC],t2.[FAQLDF],t2.[FAQLUT]," & _
"t2.[FAQLIR],t2.[FAQLWaiGuan],t2.[FAQLYaMinDianYa],t2.[FAQLLouDianLiu],t2.[FAQLXianXingXiShu]," & _
"t2.[FAQLChongJiDianLiu],t2.[FCeDianYa],t2.[FCePinLv],t2.[FCeDianRongLiangC],t2.[FCeSunHaoDF]," & _
"t2.[FCeNaiDianYaUT],t2.[FJueYuanDianZu],t2.[FCSL],t2.[FCUSL],t2.[FCLSL],t2.[FDFSL],t2.[FDFUSL]," & _
"t2.[FDFLSL],t2.[FD],t2.[FT],t2.[FF],t2.[FD_d],t2.[FL],t2.[FWenDu],t2.[FShiDu],t2.[FYaMinWaiGuan]," & _
"t2.[FYaMinDianZuChiCun],t2.[FYaMinDianYa],t2.[FLouDianLiu],t2.[FXianXingXiShu],t2.[FZuiDaChongJiDianLiu]," & _
"t2.[FJingDianRongLiang],t2.[FSunHaoQieJiao],t2.[FHuiLuDianYa],t2.[FLangYongDianYa],t2.[FNaiDianYa]," & _
"t2.[FJueYuanDianZu_1],t2.[FZuRan],t2.[FKeHanXing],t2.[FLaShengQiangDu],t2.[FWanQuQiangDu]," & _
"t2.[FCeYaMinWaiGuan],t2.[FCeYaMinDianZuChiCun],t2.[FCeYaMinDianYa],t2.[FCeLouDianLiu]," & _
"t2.[FCeXianXingXiShu],t2.[FCeZuiDaChongJiDianLiu],t2.[FCeJingDianRongLiang],t2.[FCeSunHaoZhengQieJiao]," & _
"t2.[FCeHuiLuDianYa],t2.[FCeLangYongDianLiu],t2.[FCeNaiDianYa],t2.[FCeJueYuanDianZu],t2.[FCeZuRan]," & _
"t2.[FCeKeHanXing],t2.[FCeLaShengQiangDu],t2.[FCeWanQuQiangDu],t2.[FCeShiBaoGao]," & _
"t2.[客户料号] from 项目测试数据看板  As t1" & _
"INNER JOIN 报告指标项次 As t2 ON t1.[客户对应物料代码]=t2.[客户料号]" & _
"where 项目编号=  '" & bh & "'"
这段执行就报错:无法绑定由多个部分组成的标识符"t1.批号"等等,这是什么原因?我只分行加了" & _这个啊

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
  发帖心情 Post By:2018/3/26 17:01:00 [显示全部帖子]

1可以
2,前面Dim bh As String = Forms("测试窗口").Controls("TextBox39").Value
后面
Dim q2 As new QueryBuilder
q2.TableName = "统计"
q2.SelectString = sql2
q2.C
q2.Build

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
  发帖心情 Post By:2018/3/26 17:35:00 [显示全部帖子]

老师还是不行,单独在窗口运行SQL语句(不带分行的)都正常

图片点击可在新窗口打开查看此主题相关图片如下:qq截图20180326173401.jpg
图片点击可在新窗口打开查看

[此贴子已经被作者于2018/3/26 17:35:47编辑过]

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
  发帖心情 Post By:2018/3/28 16:01:00 [显示全部帖子]

老师,命令窗口也是报上面图中一样的错,但是我把所有分行去了,连成一行,这句语句就是对的,这是什么原因?
我想分行,这样能看的清晰点也方便后面添加新的。请问如何处理?之前有句别的也是用分行处理就可以的

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
  发帖心情 Post By:2018/3/28 16:32:00 [显示全部帖子]

Dim sql2 As String ="S elect t1.[项目编号],t1.[客户名称],t1.[物料代码],t1.[物料名称],t1.[规格型号],t1.[客户对应物料代码],t1.[客户对应物料名称],t1.[实发数量],t1.[电容量单位],t1.[批号],t2.[FJianYanShuiPing],t2.[FAQLC],t2.[FAQLDF],t2.[FAQLUT],t2.[FAQLIR],t2.[FAQLWaiGuan],t2.[FAQLYaMinDianYa],t2.[FAQLLouDianLiu],t2.[FAQLXianXingXiShu],t2.[FAQLChongJiDianLiu],t2.[FCeDianYa],t2.[FCePinLv],t2.[FCeDianRongLiangC],t2.[FCeSunHaoDF],t2.[FCeNaiDianYaUT],t2.[FJueYuanDianZu],t2.[FCSL],t2.[FCUSL],t2.[FCLSL],t2.[FDFSL],t2.[FDFUSL],t2.[FDFLSL],t2.[FD],t2.[FT],t2.[FF],t2.[FD_d],t2.[FL],t2.[FWenDu],t2.[FShiDu],t2.[FYaMinWaiGuan],t2.[FYaMinDianZuChiCun],t2.[FYaMinDianYa],t2.[FLouDianLiu],t2.[FXianXingXiShu],t2.[FZuiDaChongJiDianLiu],t2.[FJingDianRongLiang],t2.[FSunHaoQieJiao],t2.[FHuiLuDianYa],t2.[FLangYongDianYa],t2.[FNaiDianYa],t2.[FJueYuanDianZu_1],t2.[FZuRan],t2.[FKeHanXing],t2.[FLaShengQiangDu],t2.[FWanQuQiangDu],t2.[FCeYaMinWaiGuan],t2.[FCeYaMinDianZuChiCun],t2.[FCeYaMinDianYa],t2.[FCeLouDianLiu],t2.[FCeXianXingXiShu],t2.[FCeZuiDaChongJiDianLiu],t2.[FCeJingDianRongLiang],t2.[FCeSunHaoZhengQieJiao],t2.[FCeHuiLuDianYa],t2.[FCeLangYongDianLiu],t2.[FCeNaiDianYa],t2.[FCeJueYuanDianZu],t2.[FCeZuRan],t2.[FCeKeHanXing],t2.[FCeLaShengQiangDu],t2.[FCeWanQuQiangDu],t2.[FCeShiBaoGao],t2.[客户物料代码] from 项目测试数据看板  As t1 INNER JOIN 报告指标项次 As t2 ON t1.[客户对应物料代码]=t2.[客户物料代码] where 项目编号= '" & bh & "'"

这句一整行的是对的,发帖的分行是错的

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
  发帖心情 Post By:2018/3/28 16:58:00 [显示全部帖子]

老师,解决了,在from前面加2个空格,在第一个INNER JOIN前加1个空格,现在可以运行了,请告知原因。
Dim sql2 As String ="S elect t1.[项目编号],t1.[客户名称],t1.[物料代码],t1.[物料名称],t1.[规格型号],t1.[客户对应物料代码],t1.[客户对应物料名称],t1.[实发数量],t1.[电容量单位],t1.[批号]," & _
"t2.[FJianYanShuiPing],t2.[FAQLC],t2.[FAQLDF],t2.[FAQLUT],t2.[FAQLIR],t2.[FAQLWaiGuan],t2.[FAQLYaMinDianYa],t2.[FAQLLouDianLiu],t2.[FAQLXianXingXiShu],t2.[FAQLChongJiDianLiu]," & _
"t2.[FCeDianYa],t2.[FCePinLv],t2.[FCeDianRongLiangC],t2.[FCeSunHaoDF],t2.[FCeNaiDianYaUT],t2.[FJueYuanDianZu],t2.[FCSL],t2.[FCUSL],t2.[FCLSL],t2.[FDFSL],t2.[FDFUSL],t2.[FDFLSL]," & _
"t2.[FD],t2.[FT],t2.[FF],t2.[FD_d],t2.[FL],t2.[FWenDu],t2.[FShiDu],t2.[FYaMinWaiGuan],t2.[FYaMinDianZuChiCun],t2.[FYaMinDianYa],t2.[FLouDianLiu],t2.[FXianXingXiShu]," & _
"t2.[FZuiDaChongJiDianLiu],t2.[FJingDianRongLiang],t2.[FSunHaoQieJiao],t2.[FHuiLuDianYa],t2.[FLangYongDianYa],t2.[FNaiDianYa],t2.[FJueYuanDianZu_1],t2.[FZuRan],t2.[FKeHanXing]," & _
"t2.[FLaShengQiangDu],t2.[FWanQuQiangDu],t2.[FCeYaMinWaiGuan],t2.[FCeYaMinDianZuChiCun],t2.[FCeYaMinDianYa],t2.[FCeLouDianLiu],t2.[FCeXianXingXiShu],t2.[FCeZuiDaChongJiDianLiu]," & _
"t2.[FCeJingDianRongLiang],t2.[FCeSunHaoZhengQieJiao],t2.[FCeHuiLuDianYa],t2.[FCeLangYongDianLiu],t2.[FCeNaiDianYa],t2.[FCeJueYuanDianZu],t2.[FCeZuRan],t2.[FCeKeHanXing]," & _
"t2.[FCeLaShengQiangDu],t2.[FCeWanQuQiangDu],t2.[FCeShiBaoGao],t2.[客户物料代码]," & _
"t3.[样本量字码],t4.[接收数],t4.[拒收数],t4.[变更样本量],t5.[接收数],t5.[拒收数],t5.[变更样本量],t6.[接收数],t6.[拒收数],t6.[变更样本量]" & _
"  from 项目测试数据看板 As t1" & _
" INNER JOIN 报告指标项次 As t2 ON t1.[客户对应物料代码]=t2.[客户物料代码]" & _
"INNER JOIN 样本量 As t3 ON t2.[FJianYanShuiPing]=t3.[检验水平]" & _
"INNER JOIN 接收质量水平表 As t4 ON t4.[接收质量水平]=t2.[FAQLC] and t4.[样本量字码]=t3.[样本量字码]" & _
"INNER JOIN 接收质量水平表 As t5 ON t5.[接收质量水平]=t2.[FAQLDF] and t5.[样本量字码]=t3.[样本量字码]" & _
"INNER JOIN 接收质量水平表 As t6 ON t6.[接收质量水平]=t2.[FAQLWaiGuan] and t6.[样本量字码]=t3.[样本量字码]" & _
"where 项目编号= '" & bh & "' and 批量= '" & pl & "'"
[此贴子已经被作者于2018/3/28 16:59:09编辑过]

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
  发帖心情 Post By:2018/3/29 15:51:00 [显示全部帖子]

嗯,知道了,谢老师
Dim min As Double = Forms("数据自动生成").Controls("TextBox1").Value
Dim max As Double = Forms("数据自动生成").Controls("TextBox2").Value
    Dim r1 As Double= Rand.Next(min*100, max*100)
    Dim r2 As Double= Rand.Next(min*100, max*100)

另,老师,如上取随机数,在同一个窗口下,点击确定后,为什么r1的随机数会等于r2的随机数,如何各取各的?

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


加好友 发短信
等级:一尾狐 帖子:481 积分:3258 威望:0 精华:0 注册:2015/6/2 8:33:00
  发帖心情 Post By:2018/3/29 16:00:00 [显示全部帖子]

老师,对的,只是最后取数的时候,r1,r2没变,都是r1,才这样,再试了下,这次正常了
[此贴子已经被作者于2018/3/29 16:02:06编辑过]

 回到顶部