Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2005, 02:19 AM
Registered User
 
Join Date: Feb 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default behaviour of NULL value in date type columns

Hi All

Table :tbl_Books
for all rows, value of book_date column is NULL.

Here are two queries
1.
SELECT top 5 Book_ISBN,isnull(book_date,'1/1/2009') from tbl_Books order by isnull(Book_Date,'') desc

2.
SELECT Book_ISBN,isnull(book_date,'1/1/2009') from tbl_Books order by isnull(Book_Date,'') desc

just difference is the required number-of-rows.

But the order of rows in both the result is different. Aditional to that If i take 'top - 1' in first query, result shows one particular row even if i tries many times.

what could be the reason

Thanks for all

Hans Raj Kasana

 
Old July 7th, 2005, 04:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure why you see the difference, I dont observe any such difference in that. In both cases it results in the same order.

_________________________
- Vijay G
Strive for Perfection
 
Old July 7th, 2005, 04:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by kasanar
But the order of rows in both the result is different.
Well, you said that all rows have NULL as the value of your column, so the ISNULL expression will also have the same value for all rows. Thus, you are ordering your resultset on a column where all values "tie". Since you give no other column for (sub)ordering, the query processor is free to return the rows in any old order it wants, as long as the rows meet your original query's ordering. Since all columns have the same value, then any ordering of the rows at all meets your ordering criteria.

The specifics of which rows are actually returned is dependent on indexes, the state of the cache at the instant the query runs, and the phases of the moon... thus you cannot depend on any order unless you specifically request it.
Quote:
quote:... If i take 'top - 1' in first query, result shows one particular row even if i tries many times.
What would you have it do? If all rows have the same value then it is certainly true that that one row meets your criteria. If you ask for the TOP 1 from a set of rows where the ordering criteria is the same for all rows, then any row is the correct answer. The one it gave you is perfectly correct.

If you have another row in mind, you need to give it more information...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Data type columns and replication SQLScott SQL Server 2005 0 May 16th, 2007 02:20 PM
Display all NULL columns hm_naveen Oracle 2 January 5th, 2007 09:50 AM
Changing Data Type Behaviour mat41 SQL Server ASP 8 August 28th, 2006 07:17 PM
How to set Not Null constraint to Null Columns arasu Oracle 1 August 22nd, 2005 10:09 AM
C# null value assignment to numerical type yossarian General .NET 1 January 21st, 2005 08:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.