Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 How do I limit a query numerically?
 New Topic  Topic Locked
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 27 October 2003 :  23:32:38  Show Profile  Visit Gremlin's Homepage
Unless you specifically wish to retrieve all fields from a database table it's better not to use '*' to liberally, for example if you had a table with 10 fields in it and you want only the value of 2 or 3 of those rows then using 'SELECT *' is a waste of resources as the database will go and retrieve all 10 values instead of just the ones you want.

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page

Alfred
Senior Member

USA
1527 Posts

Posted - 28 October 2003 :  00:26:14  Show Profile  Visit Alfred's Homepage
Good point, and believe it or not, I always considered that aspect of it.
I usually use it to test whether an error is caused by the specific selection of fields.

Alfred
The Battle Group
CREDO
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 28 October 2003 :  04:40:17  Show Profile
quote:
Originally posted by Nikkol

select top x ... works in access too. the topsql function uses rowcount for sql server.



The reason that the TopSQL function uses rowcount for SQL Server is so that it works with 6.5 which doesn't support the TOP n feature.
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 28 October 2003 :  04:51:50  Show Profile
Here's an expanded TOpSQL function with some other database platforms:

Function TopSQL(strSQL, lngRecords)
  If ucase(left(strSQL,7))="SELECT " then
    'Remove ; at the end of any SQL code
    strTempSQL=strSQL
    if right(strSQL,1)=";" then strTempSQL=left(strSQL,len(strSQL)-1)

    select case strDBType 
    case "sqlserver65"
      TopSQL="SET ROWCOUNT " & lngRecords & vbcrlf & strTempSQL & vbcrlf & "SET ROWCOUNT 0"
    case "sqlserver"
      TopSQL="SELECT TOP " & lngRecords & mid(strTempSQL,7)
    case "access"
      TopSQL="SELECT TOP " & lngRecords & mid(strTempSQL,7)
    case "mysql"
      TopSQL=strTempSQL & " LIMIT " & lngRecords
    case "oracle"
      TopSQL="SELECT * FROM (" & strTempSQL & ") WHERE ROWNUM <= " & lngRecords
    case "sybasease"
      TopSQL="SET ROWCOUNT " & lngRecords & vbcrlf & strTempSQL & vbcrlf & "SET ROWCOUNT 0"
    case "ibmdb2"
      TopSQL=strTempSQL & " FETCH FIRST " & lngRecords & " ROWS ONLY"
    end select
  Else
    TopSQL=strSQL
  End If
End Function
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.29 seconds. Powered By: Snitz Forums 2000 Version 3.4.07