Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one table having column factor datatype varchar(50
) which is blank

I used
SQL
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
SQL
select(ISNULL((select Factor1 from PR.PODTL where DocCode='FY13/PO/33'),'0.00' )) as BrokerageAmt

but no change
any help will be appreciable
regards,
shivani
Posted

i think you can try this

SQL
select COALESCE(nullif(Factor1,''),'0.00') as BrokerageAmt from podtl where DocCode='FY13/PO/33' 


Hope this will help...
 
Share this answer
 
Comments
Adarsh chauhan 10-Jul-13 3:21am    
perfect and better then mine..
+5 for this..
I learned use of coalese and nullif.. Thanks
Adarsh chauhan 10-Jul-13 3:26am    
can also use like..
select ISNULL(nullif(Factor1,''),'0.00') as BrokerageAmt from podtl where DocCode='FY13/PO/33'
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

SQL
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...
 
Share this answer
 
v4
Comments
shivani 2013 10-Jul-13 2:41am    
thanks a lot I learnt something new today...GOD bless you
Adarsh chauhan 10-Jul-13 2:43am    
Thanks.. you are most welcome...
I also learned a lot from code project, and you peoples...
:)
Try:
SQL
SELECT ISNULL(Factor1, '0.00') AS BrokerageAmt FROM PR.PODTL WHERE DocCode='FY13/PO/33'
 
Share this answer
 
Comments
Priyanka7777 10-Jul-13 2:22am    
Perfect!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900