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
 DATEETIME

Author  Topic 

yaman
Posting Yak Master

213 Posts

Posted - 2010-02-08 : 12:25:24
Hello Sir ,

How can i return balank space if date is null .

I am trying this :-

select isnull(date,'') as date from tablename .

This query return 01/01/01 if date is null
Please help me out sir .

Yaman

Kristen
Test

22859 Posts

Posted - 2010-02-08 : 12:33:07
Well you can't really (because a DATETIME datatype can only store valid dates, or NULL, it cannot store "Blank"). It would be better to format the data in the application for this need.

You could convert the date to VARCHAR and format it, and then provide a blank date when the date is NULL, but as I said it would be much better to do this in the application.

SELECT COALESCE(CONVERT(varchar(24), MyDate, 113), '')
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-08 : 12:33:49
thats because isnull makes return type as datetime so '' will returned as default date value which is 01/01/01.
for returning blank you might need to convert date to varchar. but question is why you want to do that? Isnt it enough to do this as front end?

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-10 : 06:34:23
Note that '' is not acually empty string.
http://beyondrelational.com/blogs/madhivanan/archive/2008/09/02/empty-string-and-default-values.aspx

Madhivanan

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

- Advertisement -