473,385 Members | 1,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.dtDisplayUntil, dbo.tblEvents.ID, MIN(dbo.tblDates.dtDate) as
dtDate, dbo.tblEvents.strTitle,
strDescription AS Description,
dbo.tblEvents.strLocation, dbo.tblEvents.strCost
FROM dbo.tblEvents LEFT OUTER JOIN
dbo.tblDates ON dbo.tblEvents.ID = dbo.tblDates.CID
GROUP BY dbo.tblEvents.ID, dbo.tblEvents.dtDisplayUntil,
dbo.tblEvents.strTitle, dbo.tblEvents.strDescription,
dbo.tblEvents.strLocation, dbo.tblEvents.strCost
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.tblDates.dtDate)

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


Feb 9 '06 #1
1 1040
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.NET) 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
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...
0
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...
6
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
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...
2
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...
3
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 =...
3
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...
3
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.