用整数替换NULL记录

时间:2013-12-20 05:42:19

标签: sql sql-server ssis

我的经理要我用-1替换Fact Table中的所有NULL值/记录。但是,当我将下面的脚本放在OLE DB源>> SQL命令>> SQL命令文本它不起作用。以前我尝试用整数1替换NULL记录,但他希望我用负-1替换所有NULL值而不是1.如果我在SSMS中运行下面的脚本,它工作正常!它给了我需要的结果,所有NULL值反映为-1。但是,当我把脚本放在OLE DB源>> SQL命令>> SQL命令文本,当我使用-1时它不起作用。但它仅适用于1的整数。

在部分的情况下看看我的-1。

Select 
case when d.ResourceKey is NULL then -1 else d.ResourceKey end as ResourceKey, 
convert(int,convert(varchar(8),dateadd(dd,-datepart(dw,getdate()),getdate()),112)) as TimeKey, 
case when A.AusFunctionKey is NULL then -1 else A.AusFunctionKey end as AusFunctionKey, 
case when I.IntFunctionKey is NULL then -1 else I.IntFunctionKey end as IntFunctionKey, 
case when o.RegionViewKey is NULL then -1 else o.RegionViewKey end as RegionViewKey, 
case when E.EntityKey is NULL then -1 else E.entityKey end as EmployingEntityKey,
r.ResourceID, 
r.SubSubFunctionCode, 
r.SubLocationCode, 
r.Site, 
t.SiteDesc, 
sum(t.ItemValue1) as HoursOutstanding, 
sum(t.ItemValue1 * isnull(case when t.itemvalue2 = 0 then r.CostRateRegOper else r.CostRateIntOper end,0)) as OperCostOutstanding,
sum(t.ItemValue1 * isnull(case when t.itemvalue2 = 0 then r.ChargeRateRegOper else r.ChargeRateIntOper end,0)) as OperRevenueOutstanding,
sum(t.ItemValue1 * isnull(case when t.itemvalue2 = 0 then r.CostRateRegHome else r.CostRateIntHome end,0)) as HomeCostOutstanding,
sum(t.ItemValue1 * isnull(case when t.itemvalue2 = 0 then r.ChargeRateRegHome else r.ChargeRateIntHome end,0)) as HomeRevenueOutstanding,
r.HomeCurrCode,
sum(t.ItemValue1 * isnull(case when t.itemvalue2 = 0 then r.CostRateRegNat else r.CostRateIntNat end,0)) as NatCostOutstanding,
sum(t.ItemValue1 * isnull(case when t.itemvalue2 = 0 then r.ChargeRateRegNat else r.ChargeRateIntNat end,0)) as NatRevenueOutstanding,
r.NatCurrCode 

from
ODS_CurrentResource r 
left outer join ODS_Staff_Task t 
on R.RESOURCEID = T.RESOURCEID
left outer join DWResourceTask.dbo.DimResource D
on T.RESOURCEID = D.RESOURCEID
left outer join DWResourceTask.dbo.DimAustralianFunction A
on R.SubSubFunctionCode = A.SubSubFunctionCode
left outer join DWResourceTask.dbo.DimInternationalFunction I
on R.SubSubFunctionCode = I.SubSubFunctionCode
left outer join DWResourceTask.dbo.DimRegion o
on R.SubLocationCode = o.SubLocationCode 
left outer join DWResourceTask.dbo.DimEntity E
on R.LegalEntity = E.EntCode

where r.resourcetypecode <> 'C'
and t.sitedesc = r.resourcesite
and t.TaskTypeID in (5,6) --missing time
group by d.ResourceKey, A.AusFunctionKey, I.IntFunctionKey, o.RegionViewKey, E.EntityKey, r.ResourceID, r.SubSubFunctionCode, r.SubLocationCode, r.Site, t.SiteDesc, 
t.Resourceid,r.HomeCurrCode, r.NatCurrCode

我可以使用更好的整数而不是1或-1吗?你有什么建议吗?哪个可以在SSIS中工作?

非常感谢!!

0 个答案:

没有答案