日期:2014-05-19  浏览次数:20972 次

sql语句int型减null的问题
set   ANSI_NULLS   ON
set   QUOTED_IDENTIFIER   ON
GO

ALTER   proc   [dbo].[sp_L_PurchaseSortAssetPlan]
@startDate   datetime,
@endDate   datetime
as
select   SortAssetRfCode   as   资产条码,SortAssetName   as   资产名称,spec   as   规格,units   as   单位,StockAmount   as   库存量,cCount   as   消耗量,(cCount-case   when   aCount=null   then   0   else   aCount   end)
  as   计划购买数量,remark   as   备注   from   SortAsset a
right   join   (select   SortAssetID,sum(sCount)   as   cCount   from   sortAssetDraw   c
where   sGetTime   between   @startDate   and   @endDate
group   by   SortAssetID)   tab2
on   a.SortAssetID   =   tab2.SortAssetID
left   join   (select   SortAssetID,sum(Amount)   as   aCount   from   InStoreDetail   a
left   join   InStore   b   on   a.InStoreID   =   b.InStoreID
where   InDate   between   @startDate   and   @endDate
group   by   SortAssetID)   tab1
on   a.SortAssetID   =   tab1.SortAssetID


这个存储过程中,我总得不到计划购买数量,原因是一个整数值减一个空值最后得NULL我想让空值做0,请大家帮个忙。

------解决方案--------------------
isnull(字段,0),你直接付个默认值不就可以拉~~~
------解决方案--------------------
用isnull函数,使用方法查帮助!!!
------解决方案--------------------
NULL用is判断