Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 7th, 2005, 02:19 AM
Registered User
 
Join Date: Feb 2005
Location: Faridabad, Haryana, India.
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

Reply With Quote
  #2 (permalink)  
Old July 7th, 2005, 04:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
  #3 (permalink)  
Old July 7th, 2005, 04:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:54 PM.


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