如何使用isnull摆脱错误 [英] how to get rid from error using isnull
本文介绍了如何使用isnull摆脱错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表有列因子数据类型varchar(50
)这是空白的
我使用了
I have one table having column factor datatype varchar(50
) which is blank
I used
select(ISNULL((select Factor1 from PR.PODTL where DocCode='FY13/PO/33'),0.00 )) as BrokerageAmt
但是没有影响列仍然是空白
即使我用过
but no affect column is still blank
even I used
select(ISNULL((select Factor1 from PR.PODTL where DocCode='FY13/PO/33'),'0.00' )) as BrokerageAmt
但没有变化
任何帮助都会很明显
问候,
shivani
but no change
any help will be appreciable
regards,
shivani
推荐答案
我想你可以试试这个
i think you can try this
select COALESCE(nullif(Factor1,''),'0.00') as BrokerageAmt from podtl where DocCode='FY13/PO/33'
希望这会有所帮助......
Hope this will help...
尝试:
Try:
SELECT ISNULL(Factor1, '0.00') AS BrokerageAmt FROM PR.PODTL WHERE DocCode='FY13/PO/33'
如果您的表格中包含''(空白)
使用这个...(因为isnull不处理空格...)
Hi,
if you table contains '' (blank) in your column
use this...( as isnull doesn't handle blank space...)
select case when Factor1 ='' then '0.00' when Factor1 IS null then '0.00' else Factor1 end as BrokerageAmt
from PR.PODTL where DocCode='FY13/PO/33'
否则使用
else use
select ISnull(Factor1,'0.00') as BrokerageAmt
from PR.PODTL where DocCode='FY13/PO/33'
以及更多说明见下面例如。
and for more clarification see below eg.
create table aaa
(
id int,
factor varchar(5)
)
insert into aaa values(1,'aaa')
insert into aaa values(2,'')
insert into aaa(id) values(3)
1) select * from aaa
结果:
result:
id factor
1 aaa
2
3 NULL
2) select ID, ISNULL(factor,0)as factor from aaa
结果:
result:
ID factor
1 aaa
2
3 0
3) select ID, case when Factor ='' then '0' when Factor IS null then '0' else factor end as factor
from aaa
结果:
result:
ID factor
1 aaa
2 0
3 0
希望这能解决你的问题......
Hope this will clear your problem...
这篇关于如何使用isnull摆脱错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文