壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5731|回复: 15

[库存] 查询库存现有量的SQL查询语句

[复制链接]
发表于 2008/12/24 09:07:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
各位今天我在进行库存现有量查询的时候,检查了一下系统所用的查询语句,不太清楚的是条件之中有: WHERE 1 = 0
这样的语句,请问出现这样的条件有什么原因吗?
  1. SELECT ORGANIZATION_ID,
  2. ORGANIZATION_CODE,
  3. SUBINVENTORY_CODE,
  4. LOCATOR_ID,
  5. LOCATOR,
  6. PROJECT_ID,
  7. TASK_ID,
  8. INVENTORY_ITEM_ID,
  9. ITEM_DESCRIPTION,
  10. ITEM,
  11. UOM,
  12. REVISION,
  13. ON_HAND,
  14. UNPACKED,
  15. PACKED,
  16. COST_GROUP_ID,
  17. LPN_ID,
  18. LPN,
  19. LOT_NUMBER,
  20. SERIAL_NUMBER,
  21. UNIT_NUMBER,
  22. PLANNING_ORGANIZATION_ID,
  23. PLANNING_TP_TYPE,
  24. OWNING_ORGANIZATION_ID,
  25. OWNING_TP_TYPE,
  26. SUBINVENTORY_STATUS_ID,
  27. LPN_CONTEXT,
  28. ITEM_LOT_CONTROL,
  29. ITEM_SERIAL_CONTROL
  30. FROM MTL_ONHAND_DUMMY_V
  31. WHERE 1 = 0
  32. UNION ALL
  33. SELECT organization_id,
  34. organization_code,
  35. to_char(null) subinventory_code,
  36. to_number(null) locator_id,
  37. to_char(null) locator,
  38. to_number(null) project_id,
  39. to_number(null) task_id,
  40. inventory_item_id,
  41. item_description,
  42. item,
  43. uom,
  44. to_char(null) revision,
  45. sum(on_hand) on_hand,
  46. sum(unpacked) unpacked,
  47. sum(packed) packed,
  48. to_number(null) cost_group_id,
  49. to_number(null) lpn_id,
  50. to_char(null) lpn,
  51. to_char(null) lot_number,
  52. to_char(null) serial_number,
  53. to_char(null) unit_number,
  54. planning_organization_id,
  55. planning_tp_type,
  56. owning_organization_id,
  57. owning_tp_type,
  58. to_number(null) status_id,
  59. to_number(null) lpn_context,
  60. item_lot_control,
  61. item_serial_control
  62. FROM MTL_ONHAND_TOTAL_MWB_V
  63. WHERE 1 = 1
  64. AND inventory_item_id = '966660'
  65. AND organization_id = '143'
  66. GROUP BY organization_id,
  67. organization_code,
  68. inventory_item_id,
  69. item_description,
  70. item,
  71. uom,
  72. planning_organization_id,
  73. planning_tp_type,
  74. owning_organization_id,
  75. owning_tp_type,
  76. item_lot_control,
  77. item_serial_control
  78. HAVING 1 = 1
  79. UNION ALL
  80. SELECT organization_id,
  81. organization_code,
  82. subinventory_code,
  83. locator_id,
  84. locator,
  85. project_id,
  86. task_id,
  87. inventory_item_id,
  88. item_description,
  89. item,
  90. uom,
  91. revision,
  92. on_hand,
  93. unpacked,
  94. packed,
  95. cost_group_id,
  96. lpn_id,
  97. lpn,
  98. lot_number,
  99. serial_number,
  100. unit_number,
  101. planning_organization_id,
  102. planning_tp_type,
  103. owning_organization_id,
  104. owning_tp_type,
  105. subinventory_status_id,
  106. lpn_context,
  107. item_lot_control,
  108. item_serial_control
  109. FROM mtl_onhand_dummy_v
  110. WHERE 1 = 0
  111. order by ITEM, ORGANIZATION_ID, SUBINVENTORY_CODE, LOCATOR
复制代码

点评

参考表 mtl_onhand_quantities  发表于 2012/5/8 15:06
发表于 2008/12/24 23:37:10 | 显示全部楼层
GOOD~~ 推~~
发表于 2008/12/25 08:15:49 | 显示全部楼层
where 1=0 是個羅輯判斷呀,結果是沒有任何記錄。
发表于 2008/12/25 12:21:24 | 显示全部楼层
可以看成是sql语句的开关
发表于 2008/12/25 15:16:30 | 显示全部楼层
相当于逻辑判断结果=false
发表于 2009/1/9 17:22:01 | 显示全部楼层
4楼说的没错,就是开关语句,直接加上这句SQL就等于停掉,什么也找不到,我自己的程式有时也会这样做.
发表于 2009/1/11 23:48:04 | 显示全部楼层
good  ~~   ^^
发表于 2009/1/16 13:20:24 | 显示全部楼层
常见的还有WHERE 1=1 呢,一些程序里查询里为拼接SQL语句用。
发表于 2009/1/22 09:57:34 | 显示全部楼层
加上where 1=0 或1=1 在写程序的时候方便添加条件。
发表于 2012/5/8 14:52:57 | 显示全部楼层
{:soso_e100:}
发表于 2012/5/8 15:06:44 | 显示全部楼层
参考表 mtl_onhand_quantities
发表于 2012/11/9 08:16:34 | 显示全部楼层
GOOD~~ 推~~
发表于 2012/11/9 12:34:33 | 显示全部楼层
SELECT msk.concatenated_segments AS 物料编码,
       msk.description AS 物料描述,
       msk.primary_unit_of_measure AS 单位,
       ood.organization_name AS 库存组织,
       msi.secondary_inventory_name AS 子库,
       mlk.concatenated_segments AS 货位,
       moq.lot_number AS 批次,
       SUM(moq.primary_transaction_quantity) AS 数量
  FROM mtl_onhand_quantities_detail moq,
       mtl_system_items_kfv         msk,
       org_organization_definitions ood,
       mtl_secondary_inventories    msi,
       mtl_item_locations_kfv       mlk
WHERE moq.inventory_item_id = msk.inventory_item_id
   AND moq.organization_id = msk.organization_id
   AND moq.organization_id = ood.organization_id
   AND moq.subinventory_code = msi.secondary_inventory_name
   AND msk.serial_number_control_code = 1
   AND moq.locator_id = mlk.inventory_location_id(+)
发表于 2012/11/9 13:11:53 | 显示全部楼层
where 1=1经常用
where 1=0没用过
发表于 2012/11/13 17:17:52 | 显示全部楼层
1=0 false
1=1经常用的 查现有量ONhead就可以吧。。。。
发表于 2012/11/14 10:30:28 | 显示全部楼层
学习中。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 03:45 , Processed in 0.019398 second(s), 19 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表