免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2895 | 回复: 5
打印 上一主题 下一主题

突然之间脑子晕了,什么都想不明白了 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-24 12:05 |只看该作者 |倒序浏览

  1.                 string strSQL = "";
  2.                 strSQL = @"select * from rejectnotify a ,checkupinfo b,barcodeinfo c,partinfo d,procedure e where a.rejectnotifyno=b.rejectnotifyno and a.barcode = c.barcode and c.partno=d.partno and b.poid=e.oid";
  3.                 if (sTM != "") strSQL = strSQL + " and a.barcode ='" + sTM + "'";
  4.                 if (sBH != "") strSQL = strSQL + " and a.rejectnotifyno ='" + sBH + "'";
  5.                 if (sShopNo != "") strSQL = strSQL + " and e.ShopNo ='" + sShopNo + "'";
  6.                 if (sProcedure != "") strSQL = strSQL + " and e.ProcedureNo ='" + sProcedure + "'";
  7.                 if (sShopNo1 != "") strSQL = strSQL + " and a.DutyShop ='" + sShopNo1 + "'";
  8.                 if (sProcedure1 != "") strSQL = strSQL + " and a.DutyProcedure ='" + sProcedure1 + "'";
  9.                 if (sChecker != "") strSQL = strSQL + " and a.Checker ='" + sChecker + "'";
  10.                 if (sDate1 != "") strSQL = strSQL + " and date(a.CheckUpDate) >=to_date('" + sDate1 + "','%Y-%m-%d')";
  11.                 if (sDate2 != "") strSQL = strSQL + " and date(a.CheckUpDate) <=to_date('" + sDate2 + "','%Y-%m-%d')";
  12.                 if (sCheckUp != "") strSQL = strSQL + " and a.ProcessMode ='" + sCheckUp + "'";
  13.                 if (sState != "") strSQL = strSQL + " and a.State ='" + sState + "'";
  14.                 if (sAuditing != "") strSQL = strSQL + " and a.AuditingResult ='" + sAuditing + "'";
  15.                 OdbcCommand commandDtl3 = new OdbcCommand(strSQL, conn);
复制代码


if里面的是查询条件
第一句是干什么用的为什么不直接用strSQL = @"select * from rejectnotify

[ 本帖最后由 lrg223 于 2008-10-24 14:09 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-10-24 14:04 |只看该作者

  1.                 string strSQL = "";
  2.                 strSQL = @"select * from rejectnotify  where oid=oid";
  3.                 if (sTM != "") strSQL = strSQL + " and barcode ='" + sTM + "'";
  4.                 if (sBH != "") strSQL = strSQL + " and rejectnotifyno ='" + sBH + "'";
  5.                 if (sShopNo != "") strSQL = strSQL + " and ShopNo ='" + sShopNo + "'";
  6.                 if (sProcedure != "") strSQL = strSQL + " and ProcedureNo ='" + sProcedure + "'";
  7.                 if (sShopNo1 != "") strSQL = strSQL + " and DutyShop ='" + sShopNo1 + "'";
  8.                 if (sProcedure1 != "") strSQL = strSQL + " and DutyProcedure ='" + sProcedure1 + "'";
  9.                 if (sChecker != "") strSQL = strSQL + " and Checker ='" + sChecker + "'";
  10.                 if (sDate1 != "") strSQL = strSQL + " and date(CheckUpDate) >=to_date('" + sDate1 + "','%Y-%m-%d')";
  11.                 if (sDate2 != "") strSQL = strSQL + " and date(CheckUpDate) <=to_date('" + sDate2 + "','%Y-%m-%d')";
  12.                 if (sCheckUp != "") strSQL = strSQL + " and ProcessMode ='" + sCheckUp + "'";
  13.                 if (sState != "") strSQL = strSQL + " and State ='" + sState + "'";
  14.                 if (sAuditing != "") strSQL = strSQL + " and AuditingResult ='" + sAuditing + "'";
  15.                 OdbcCommand commandDtl3 = new OdbcCommand(strSQL, conn);
复制代码


跟这样写有什么区别?

[ 本帖最后由 lrg223 于 2008-10-24 14:12 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2008-10-28 15:45 |只看该作者
这是联表查询啊,在where条件里加了限制啊

论坛徽章:
0
4 [报告]
发表于 2008-10-28 16:07 |只看该作者
原帖由 tradewind 于 2008-10-28 15:45 发表
这是联表查询啊,在where条件里加了限制啊


问题是需要查询的字段a和e里就包括了,那b和c有什么必要呢?这样的例子还有多处,有的所有字段都在a里也还是这样,如果说a 里字段不全,那这样查询是必要的,可是a里都有,那这样做的目的的?

论坛徽章:
0
5 [报告]
发表于 2008-10-28 17:03 |只看该作者
如果查询的字段a里都有的话,可以改成:
select * from rejectnotify a ,checkupinfo a,barcodeinfo a,partinfo a,procedure a where a.rejectnotifyno=b.rejectnotifyno and a.barcode = c.barcode and c.partno=d.partno and b.poid=e.oid";

但是where条件里的b、c、d就不能改了

论坛徽章:
0
6 [报告]
发表于 2008-10-28 17:46 |只看该作者
原帖由 tradewind 于 2008-10-28 17:03 发表
如果查询的字段a里都有的话,可以改成:
select * from rejectnotify a ,checkupinfo a,barcodeinfo a,partinfo a,procedure a where a.rejectnotifyno=b.rejectnotifyno and a.barcode = c.barcode and c.par ...


我一开始就是把他的代码复制过来然后发现数据重复了,当我打算修改的时候突然想不明白这样做的原因了,如果要找的字段在a里都有,那a里的数据是不会重复的,而这样select是用在初始界面查询时,也就是没有任何查询条件,那就应该是select *啊,还要后面的判断干什么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP