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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Show blank instead of zero date value

Author  Topic 

Humate
Posting Yak Master

101 Posts

Posted - 2007-12-14 : 09:42:54
Hi All,

I have an SQL query that returns results as I want to see them, code below.

select
[id]

,max(case when [Name] = 'HKT' then [date] else '' end) as [Results]

from Outcomes
group by [id]


The reults column returns the date for each id, but when this is zero in the data, it is entered as 1900-01-01 00:00:00.000. Can I change my query so that when the date is returned in this format, to just show the cell blank in the results?

Thanks in advance
Humate

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-14 : 09:57:44

Try

select
[id]

,max(NULLIF(case when [Name] = 'HKT' then [date] else '' end,'')) as [Results]

from Outcomes
group by [id]


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-14 : 09:59:28
No "Do it in the Front-End", Madhi?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-12-14 : 10:02:40
select
[id]

,max(case when [Name] = 'HKT' then [date] else Null end) as [Results]

from Outcomes
group by [id]

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-14 : 10:02:45
quote:
Originally posted by harsh_athalye

No "Do it in the Front-End", Madhi?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"


Now-a-days no one is listening to me

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Humate
Posting Yak Master

101 Posts

Posted - 2007-12-14 : 10:30:20
Thanks both, that does the trick!

I realise I should be doing it in the front end, but this makes things easier to understand in my small brain
Go to Top of Page
   

- Advertisement -