SQL

SELECT dbo.CBO_Category_Trl.combinename as 分类,dbo.InvTrans_TransLine.COSTUOMQTY AS 数量,dbo.CBO_Wh_Trl.name as 仓库

FROM [dbo].[InvTrans_TransLine]

left join dbo.CBO_ItemMaster on dbo.CBO_ItemMaster.id=dbo.InvTrans_TransLine.iteminfo_itemid

left join dbo.CBO_Category_Trl on dbo.CBO_ItemMaster.mainitemcategory=dbo.CBO_Category_Trl.id

left join dbo.CBO_Category on dbo.CBO_Category.id=dbo.CBO_Category_Trl.id

left join dbo.Base_Organization_Trl on dbo.Base_Organization_Trl

.id=dbo.CBO_Category.org

left join dbo.CBO_Wh_Trl on dbo.CBO_Wh_Trl.id=dbo.InvTrans_TransLine.wh

where 

dbo.Base_Organization_Trl.name='宁波培源股份有限公司'

and 

dbo.CBO_Wh_Trl.name='辅料仓'

/*and

YEAR(GETDATE()) = YEAR(dbo.InvTrans_TransLine.CREATEDON)

AND MONTH(GETDATE()) = MONTH(dbo.InvTrans_TransLine.CREATEDON)*/

and

dbo.InvTrans_TransLine.docno like '%RCV%' or 

dbo.InvTrans_TransLine.docno like '%MiscRcv%' or 

dbo.InvTrans_TransLine.docno like '%TranIn%'  or 

dbo.InvTrans_TransLine.docno like '%Borrow%'

or 

dbo.InvTrans_TransLine.docno like '%WG%'

image.png

where dbo.CBO_Wh_Trl.name='辅料仓' 已经加了这条件为什么还是会显示其他仓库信息

SQL zysf8GJV 发布于 2024-10-9 16:09
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共4回答
最佳回答
1
snrtuemcLv8专家互助
发布于2024-10-9 16:10

后面的or的括号括起来

SELECT dbo.CBO_Category_Trl.combinename as 分类,dbo.InvTrans_TransLine.COSTUOMQTY AS 数量,dbo.CBO_Wh_Trl.name as 仓库

FROM [dbo].[InvTrans_TransLine]

left join dbo.CBO_ItemMaster on dbo.CBO_ItemMaster.id=dbo.InvTrans_TransLine.iteminfo_itemid

left join dbo.CBO_Category_Trl on dbo.CBO_ItemMaster.mainitemcategory=dbo.CBO_Category_Trl.id

left join dbo.CBO_Category on dbo.CBO_Category.id=dbo.CBO_Category_Trl.id

left join dbo.Base_Organization_Trl on dbo.Base_Organization_Trl

.id=dbo.CBO_Category.org

left join dbo.CBO_Wh_Trl on dbo.CBO_Wh_Trl.id=dbo.InvTrans_TransLine.wh

where 

dbo.Base_Organization_Trl.name='宁波培源股份有限公司'

and 

dbo.CBO_Wh_Trl.name='辅料仓'

/*and

YEAR(GETDATE()) = YEAR(dbo.InvTrans_TransLine.CREATEDON)

AND MONTH(GETDATE()) = MONTH(dbo.InvTrans_TransLine.CREATEDON)*/

and

(dbo.InvTrans_TransLine.docno like '%RCV%' or 

dbo.InvTrans_TransLine.docno like '%MiscRcv%' or 

dbo.InvTrans_TransLine.docno like '%TranIn%'  or 

dbo.InvTrans_TransLine.docno like '%Borrow%'

or 

dbo.InvTrans_TransLine.docno like '%WG%')

最佳回答
0
FuFuLv5初级互助
发布于2024-10-9 16:12

OR条件

最佳回答
0
小潘同學Lv5初级互助
发布于2024-10-9 16:13

image.png

SQL先执行and,再执行or,你这一段or的用括号括起来

最佳回答
0
用户k6280494Lv6资深互助
发布于2024-10-9 16:13

SELECT

dbo.CBO_Category_Trl.combinename AS 分类,

dbo.InvTrans_TransLine.COSTUOMQTY AS 数量,

dbo.CBO_Wh_Trl.name AS 仓库 

FROM

[dbo].[InvTrans_TransLine]

LEFT JOIN dbo.CBO_ItemMaster ON dbo.CBO_ItemMaster.id= dbo.InvTrans_TransLine.iteminfo_itemid

LEFT JOIN dbo.CBO_Category_Trl ON dbo.CBO_ItemMaster.mainitemcategory= dbo.CBO_Category_Trl.id

LEFT JOIN dbo.CBO_Category ON dbo.CBO_Category.id= dbo.CBO_Category_Trl.id

LEFT JOIN dbo.Base_Organization_Trl ON dbo.Base_Organization_Trl.id= dbo.CBO_Category.org

LEFT JOIN (SELECT * from dbo.CBO_Wh_Trl WHERE name='辅料仓') ON dbo.CBO_Wh_Trl.id= dbo.InvTrans_TransLine.wh 

WHERE

dbo.Base_Organization_Trl.name= '宁波培源股份有限公司' 

  • 5关注人数
  • 66浏览人数
  • 最后回答于:2024-10-9 16:13
    请选择关闭问题的原因
    确定 取消
    返回顶部