473,761 Members | 3,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT TOP 12 Skips one!

Howdy,

Below is my SELECT statement. The returned list is suppose to return the TOP
12 when sorted by MIN(dtDate). It sorts the records correctly and only
displays 12 records, but to meet the 12 record criteria, it removes a record
that should be #6. If I change the 12 to a 13, that missing record appears,
however now its 13 and not 12. The UNION is to add a blank record at the end
so i can capture the last record in my DataList to display something
special, which works great. If I remove the UNION statement and keep it at
TOP 12, it works properly, it selects the top 12. Is there something I'm
missing on this UNION???

Thanks!!
(SELECT TOP 12
dbo.tblEvents.d tDisplayUntil, dbo.tblEvents.I D, MIN(dbo.tblDate s.dtDate) as
dtDate, dbo.tblEvents.s trTitle,
strDescription AS Description,
dbo.tblEvents.s trLocation, dbo.tblEvents.s trCost
FROM dbo.tblEvents LEFT OUTER JOIN
dbo.tblDates ON dbo.tblEvents.I D = dbo.tblDates.CI D
GROUP BY dbo.tblEvents.I D, dbo.tblEvents.d tDisplayUntil,
dbo.tblEvents.s trTitle, dbo.tblEvents.s trDescription,
dbo.tblEvents.s trLocation, dbo.tblEvents.s trCost
HAVING (dbo.tblEvents. dtDisplayUntil >= GETDATE()))
UNION
SELECT GETDATE() + 360 as dtDisplayUntil, 0 as ID, GETDATE() + 360 as
dtDate, '' as strTitle, '' as description, '' as strLocation, '' as strcost
ORDER BY MIN(dbo.tblDate s.dtDate)

--
David Lozzi
Web Applications Developer
dlozzi@(remove-this)delphi-ts.com


Feb 9 '06 #1
1 1051
Hi David

Thanks for your posting.
From your description, I understand that one of your asp.net page use
ADO.NET code to query top 12 rows from the a certain table and add an extra
row by using the UNION clause; the expected result is 13 rows. However, you
only get 12 rows actually, correct? If there is anything I misunderstand,
please feel free to let me know.

To simplified the problem for testing, I create a table with two varchar
columns, and test a simple SQL with UNION clause, unfortunately I haven't
been able to reproduce the problem through the test tables, it just returns
the 13 rows as expected. So the problem might not about the UNION clause,
to separate the issue, I suggest you test the first SQL statement without
the UNION clause, to confirm whether it is statement-specific problem or
not. Also, you can try testing the same UNION logic through some other
tables to verify my test result.

BTW, since this is likely a pure T-SQL issue, I also suggest you try
posting in SQLServer or any other DB related newsgroup(ADO.N ET) to see
whether there're any other members can help.

If you have any further information related to this problem, please feel
free to post here.
Thanks very much and looking forward to hearing from you.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Feb 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2044
by: ST | last post by:
Hi, I'm trying to debug someone else's code, and I'm going thru this Select Case statement. I'm having problems with the "OTHER" case...in that when the first line of the case is false, it jumps to the end of the select case block, instead of finishing going thru the rest of the cases (and thereby reaching the next "OTHER" case). Can anyone explain this to me?? Thanks! I've put ***** where things seems to mess up! Select Case...
0
993
by: pwinward | last post by:
Using C++ .NET 2003 and getting: "The breakpoint will not currently be hit. No executable code is associated with this line." My app links to my static library and when I try debugging either one, I can't debug any code from the library it calls, although I can debug the main app. It skips over the breakpoint even if I try setting it after starting the debugger. This is true if I set the breakpoint by function name or line number.
6
1917
by: BlueDragon | last post by:
Grrr! I'm trying to run a script: print 'Declaring cursor' declare cInv cursor forward_only static for select distinct inv.company, inv.contact, inv.address1, inv.city,
3
4756
by: bellefy | last post by:
Hi All, I have a fairly large table with approx 30K rows that updates every night via a cron script that automatically downloads the 2 new csv's. The problem is the files are downloaded from two completely different systems and I've recently found duplicates! To make matters worse, the two feeds do not share a common unique key.
2
3899
by: Eddy Bee | last post by:
Hi there, I'm encountering an inexplicable problem with page formatting in reports. Here's the easiest way to explain it: The Detail section of my report contains two elements: And let's say I have the following VB code for the Detail_Format event:
3
3398
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL = "" if i = 1 then strURL = "redirect.aspx?page=APIQ&parcel=" & strParcel &
3
3039
by: maya | last post by:
http://www.msnbc.msn.com/id/16673873/site/newsweek/ pls scroll down, on the left, near the middle, there is a select object above which it says "Newsweek Business Directory".. how do they get the alternate background colors on the list? (I looked @ src code, couldn't find "<select" ) thank you..
3
1222
by: vegtard | last post by:
by now, you have no doupt replied to many of mine and my buddy (børntard)'s questions about our faulty programming concerning the over-complicated mega-script to design your dungeons and dragons roleplaying character. well, i think i have cracked it. but theres one slight problem i cant seem to get my head wrapped around. i have an IF-statement in my script. well, i have a rediculous ammount actually. but my script skips one of them, and its...
1
8063
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just a commandbutton on my form). The biggest problem I'm having is that I can't (don't know how) populate a combobox on static items such as "True, False, Any." The Any field, would be selected by the user to find all records where that fields is...
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9336
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.