Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query help

Author  Topic 

mavershang
Posting Yak Master

111 Posts

Posted - 2009-11-04 : 16:00:57
Hi there. Here is my problem.

table is like
A B
10 20
11 21
...

select case when A is null then '0' else cast(A as varchar(2)) end
from table
where B = @Param

Now if there is no match result, it return blank but not null, therefor, nothing displayed. My question is how to treat this blank as Null so there is sth displayed.

Thanks

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2009-11-04 : 23:15:23
I'm not really sure if this is what you want, actually, I'm not really sure why you'd want a null, but just for the sake of it...

it sounds like you want this:
select case when A is null then '0' else cast(A as varchar(2)) end 
from @test
where B = @Param
union
select null as result
from table
where not exists (select B from table where B=@param)


--
I'm not schooled in the science of human factors, but I suspect that surprise is not an element of a robust user interface.
Go to Top of Page
   

- Advertisement -