Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 28th, 2004, 10:29 AM
apex apex is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 3 apex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MS SQL Limit number of records returned (n00b)

Hello all! I am a new green web designer fresh out of college. I didn't have the luxury of being taught MS SQL in school, but I did learn mySQL.

For my current project I am converting an old website to MS SQL from Access. Despite the weird changes that had to be done to the code to get things to work, it's gone smoothly otherwise.

The problem is that on this one query that I create, I need to limit the range of rows that come out.

I've looked the internet over high and low, even paying some sites that claimed to have the answer (lesson learned).

What I'm trying to do is this QUERY:
SELECT *,navigation.pageid AS nPageid FROM [pagetext] INNER JOIN [navigation] ON pagetext.[index] = navigation.pageid WHERE pagetext.[index] = navigation.pageid AND pagetext.bDelete = 0 ORDER BY document LIMIT 20,30

or more sepcifaiclly
"SELECT *,navigation.pageid AS nPageid FROM [pagetext] INNER JOIN [navigation] ON pagetext.[index] = navigation.pageid WHERE pagetext.[index] = navigation.pageid AND pagetext.bDelete = 0 ORDER BY document LIMIT " & var1 & " , " & var2 & " ;"



I've searched the net, and the closest thing I could find that could do this is
SELECT TOP 20

That doesn't have a range you can select (20-30)

Reply With Quote
  #2  
Old May 28th, 2004, 02:19 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
Basically there is no equivalent to the 2-argument LIMIT in MS SQL Server, at least not that I'm aware of.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old May 28th, 2004, 02:25 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
It appears you may be trying to create some sort of record paging on your site?
SQL Server doesn't support a select range type of query.
If you are trying to create paging, there are several examples on this forum of how to go about doing it.

Reply With Quote
  #4  
Old May 31st, 2004, 09:38 AM
apex apex is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 3 apex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes, I'm currently using the Recordset fucntions to controll what gets outputted. But the problem remains about re-inserting things into the page. The Limit function in mySQL would have worked as a perfect solution. I Guess I'll either write an angry letter to microsoft threathening to buy their company via hostile take over..... or find another way of doing what I've been working.

Reply With Quote
  #5  
Old May 31st, 2004, 01:05 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
Hmmm, I'd go with the letter ...

Reply With Quote
  #6  
Old July 20th, 2004, 03:05 PM
ckohtz ckohtz is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 ckohtz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I needed the same question answered. I read this forum first and saw there was no answer. After I found the answer, I thought I would post it here. Here it is...

select top 20 * from table where pkc not in (select top 10 pkc from t order by pkc) order by pkc

Reply With Quote
  #7  
Old September 30th, 2004, 10:45 AM
drig drig is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Denver, CO
Posts: 1 drig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to drig Send a message via MSN to drig Send a message via Yahoo to drig
For Java Developers - No ? parameter to top

Quote:
Originally Posted by ckohtz
I needed the same question answered. I read this forum first and saw there was no answer. After I found the answer, I thought I would post it here. Here it is...

select top 20 * from table where pkc not in (select top 10 pkc from t order by pkc) order by pkc


Thanks for the tip. One problem I found with this method is that it doesn't support parameterized values from within Java. So, this:

Code:
int size = 10;
PreparedStatement stmt = connection.prepareStatement
("SELECT top ? * FROM users WHERE lastname=?");
stmt.setInt (1, size);
stmt.setString (2, "McNealy");


won't work. You'll have to use string concatentation instead. Like this:

Code:
int size = 10;
PreparedStatement stmt = connection.prepareStatement
("SELECT top "+size+" * FROM users WHERE lastname=?");
stmt.setString (1, "McNealy");


-Dae

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > MS SQL Limit number of records returned (n00b)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT