Search code examples
sqldatetimesybasesap-ase

Order by on Two Datetime Fields .If one field is Null How to avoid Sybase from populating it with default datetime


I am using a Select Query to insert data into a Temp Table .In the Select Query I am doing order by on two columns something like this

insert into #temp 

Select accnt_no,acct_name, start_date,end_date From table 

Order by start_date DESC,end_date DESC
Select * from #temp

Here when there is an entry present in start_date field and an Null entry in the end_date field .During the order by operation Sybase is filling it with an Default date ( jan 1 1900 ) . I dont want that to happen .If the end_date field is Null . The data should be written just as Null .Any suggestion on how to keep it as Null even while fetching the data from the table .


Solution

  • The 1/1/1900 usually comes from trying to cast an empty string into a datetime.

    Is your 'date' source column an actual datetime datatype or a string-ish varchar or char?