Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Avoid 01-01-1900 00:00:00.000 in my select statement
Message
 
À
26/12/2008 05:44:20
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01369735
Message ID:
01369776
Vues:
9
>Hello, I'm trying to do a simple select but is displaying in two of my datetime columns the result 01-01-1900 00:00:00.000 even when the value is NULL. Is there a way to avoid this?

Hi Edgar,
The result is null when the value is null and 01-01-1900 00:00:00.000 when the value is 01-01-1900 00:00:00.000.

When you insert blank date in datetime field the result is 01-01-1900 00:00:00.000
Try this sample code
create table #crsTest
            (MyInt Int
            ,[MyDateTime] [datetime] NULL DEFAULT (NULL))

INSERT INTO #crsTest (MyInt) VALUES(1)
INSERT INTO #crsTest (MyInt) VALUES(2)
INSERT INTO #crsTest (MyInt,MyDateTime) VALUES(3,'')
INSERT INTO #crsTest (MyInt) VALUES(4)
INSERT INTO #crsTest (MyInt,MyDateTime) VALUES(5,'20081226 15:05:09')

SELECT * from #crsTest ORDER BY MyInt

SELECT MyInt,
       CASE WHEN MyDateTime = '1900-01-01' THEN NULL ELSE MyDateTime END
  from #crsTest ORDER BY MyInt

drop table #crsTest
_______________________________________________________________
Testing displays the presence, not the absence of bugs.
If a software application has to be designed, it has to be designed correctly!
_______________________________________________________________
Vladimir Zografski
Systems Analyst
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform