Current location: Hot Scripts Forums » Programming Languages » ASP » SQL Syntax Question


SQL Syntax Question

Reply
  #1 (permalink)  
Old 03-29-04, 09:41 AM
Daemon Daemon is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Virginia
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
SQL Syntax Question

I'm trying to create an SQL query, but I only want to return a certain number of records per page, but I might also want to exceed that amount in certain circumstances.

Here's my situation:
I am listing addresses, and sorting them by city. I only want to show 20 per page, but if there are 3 cities, and 2 have 6 each, and the third has 10, there would be a total of 22 records I need to display on that page, because I don't want to split the records if they have the same city. And vice versa, there are 2 cities, and the first has say 15 entries, and the second has 14, I only want to show the first city, and have the second display on a new page. Is there a way to do this just with SQL, or am I going to have to program it? I'm guessing it'd be more on the programming side, and I have an idea of how to do it.

I've checked into using LIMIT, but I don't think MSSQL has that syntax built into it, and its a MySQL only deal. Is this true?

I'm thinking I would create a query to get the records, count how many per each city, add totals and display only a certain amount per page depending on city. Any other suggestions on how to get this done? Thanks.
Reply With Quote
  #2 (permalink)  
Old 03-29-04, 12:04 PM
MadDog MadDog is offline
Code Master
 
Join Date: Aug 2003
Posts: 935
Thanks: 0
Thanked 0 Times in 0 Posts
Whats wrong with using "TOP 20" in the SQL statement?
__________________
Drew Gauderman
ASP - MSSQL Coder / Buisness Owner / Coder for Hire!
MSN-ICQ-AIM-YIM in Profile

http://www.iportalx.net an easy ASP portal system.
Reply With Quote
  #3 (permalink)  
Old 03-29-04, 01:55 PM
Daemon Daemon is offline
Newbie Coder
 
Join Date: Oct 2003
Location: Virginia
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
I did that actually, but I don't necessarily want just the top 20, I want to be able to have certain parts showing.

Anyways, I got it working after 3 hours of sitting here messing with things. Thanks though!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help on error in SQL syntax eric1328 PHP 1 02-14-04 12:08 AM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 10:22 AM
ERROR in SQL syntax near DATE_FORMAT() bitesize PHP 1 01-09-04 09:22 PM
SQL Code Syntax error...need help...missing operator geneane ASP 3 09-02-03 07:39 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 04:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.