我希望表中的null条件为零

时间:2017-11-24 04:44:56

标签: sql-server

Flight[1].seatsAvail = 101;

我想将空值更改为零 然后我想使用条件执行

3 个答案:

答案 0 :(得分:0)

您还可以使用coalesce,它将返回第一个非空值。

@Id
@GenericGenerator(name = "sequence_generator", strategy = "yourpackage.CustomIdGenerator")
@GeneratedValue(generator = "sequence_generator")
@Column(name  = "id")
private Long id;

答案 1 :(得分:0)

您也可以使用ISNULL功能

ISNULL(Your_Column, 0)

答案 2 :(得分:0)

如果我理解正确你需要ISNULL:

select * from  
(select 
    ISNULL(b.state, 0) state, 
    ISNULL(b.Region, 0) Region, 
    ISNULL(b.Area, 0) Area, 
    ISNULL(b.Sector, 0) Sector, 
    ISNULL(b.Zone, 0) Zone, 
    ISNULL(a.Mobile, 0) Mobile, 
    ISNULL(a.Mason_code, 0) Mason_code,
    ISNULL(a.Mason_Name, 0) Mason_Name,
    ISNULL(a.M_address, 0) M_address,
    ISNULL(c.CustomerRef, 0) CustomerRef,
    ISNULL(c.NoOfBags, 0) NoOfBags,
    ISNULL(c.offtakedate, 0) offtakedate,
    ISNULL(datepart(day,offtakedate), 0) as [day]
from Rmcl_Mason_dtl as a,MACE_Rep_Area_Master as b,
    RMCL_MACEAPP_Offtake_Dtl as c
where 
    a.State=b.State_Code
    and a.Region=b.Region_Code
    and a.Zone=b.Zone_Code
    and a.Area=b.Area_Code
    and a.Sector=b.Sector_Code
    and c.MasonNo=a.Mobile
    and MONTH([OfftakeDate]) = 10 AND YEAR([OfftakeDate]) = 2017
    and NoOfBags IS not null
group by 
    b.state,b.Region,b.Area,b.Sector,b.Zone,a.Mobile,a.Mason_code,
    a.Mason_Name,a.M_address,c.customerRef,c.NoOfBags,c.offtakeDate