CAST NULL DATE TO CHAR

emi_sastra
emi_sastra used Ask the Experts™
on
Hi All,

I have date data that have null value.

How could I query to make it empty string when show to datagridview?

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Not entirely sure this works for a date field, but try

NVL(datefield, '')

What NVL does is check to see if the data field contains a NULL value. If it doesn't, it returns the data from that field. But if it is NULL, it returns the value in the second argument, in this case an empty string. (note: replace the word 'datefield' with the fieldname of the date field you are querying)
Bhavesh ShahLead Analyst
Top Expert 2010

Commented:

Hi,

use IsNull(datefield,'').

Author

Commented:
Hi TRW-Consult,

What database server use NVL, never heard of that ?

Thank you.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Author

Commented:
Hi Brichsoft,

I have tried it before, but still get 01/01/1900.

Thank you.
Lead Analyst
Top Expert 2010
Commented:
Hi,

NVL - is ORACLE function.Hence you didnt specified any specific zone so expert posted.

I have tried it before, but still get 01/01/1900.
- In database,I'm assuming datefield clumn valeu is 01/01/1900

As it is datetime field,so if u put '' then it will convert as 01/10/1900.

CAST(IsNull(CONVERT(VARCHAR(10),datetime,103),'') AS VARCHAR(10))

Author

Commented:
>> Hence you didnt specified any specific zone so expert posted.
I have provided at Tags. May be I should provided at zone.

It works.

Thank you very much for your help.
Bhavesh ShahLead Analyst
Top Expert 2010

Commented:
oh yes.
I didnt see that.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial