如何在选择查询中生成空字段 [英] How do I produce a null field in a select query
本文介绍了如何在选择查询中生成空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面的查询中给出了结果
I have this below query which gives the result
Select distinct a.Item_Name, b.Item_Rate, b.professional_Charge, c.discount , c.discount_Type,
a.Dept_ID, c.Discount_Applicability
From Item_M a
left outer join Rate_M b on a.Item_Code = b.Bill_Item
left outer join Discount_M c on a.Item_Code = c.Item_Code
Where a.Item_code = 'ABS002' and b.Rate_Cat_ID = 'DLX' and
c. Pay_Type_Id='BD'
Item_Name Item_Rate professional_Charge discount discount_Type Dept_ID Discount_Applicability
ABSESS I & D 440 NULL 0 P CBN I
当我更改a.Item_code时,
将显示空白结果,除非Item_M中有项目代码table是一个完美的查询执行示例。
但我需要的优先输出是显示item_code以及空值。
when i change the a.Item_code blank result will be displayed unless the item code is present in Item_M table which is a perfect example of query execution.
But the preffered output i need is to display the item_code along with the null values along with it.
推荐答案
您需要从保证记录存在的源获取item_code,或者您可以制作此类源。此外,您需要将过滤器移出where子句。
You need to get the item_code from a source where the record is guaranteed to exist or you can manufacture such a source. Furthermore you need to move the filters out of the where clause.
Select distinct a.Item_Name, b.Item_Rate, b.professional_Charge, c.discount, c.discount_Type, a.Dept_ID, c.Discount_Applicability
From (values ('ABS002')) as x(Item_code)
left outer join Item_M a on x.Item_code = a.Item_Code
left outer join Rate_M b on a.Item_Code = b.Bill_Item and b.Rate_Cat_ID = 'DLX'
left outer join Discount_M c on a.Item_Code = c.Item_Code and c.Pay_Type_Id='BD'
这篇关于如何在选择查询中生成空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文