Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL SELECT - How to do a Fast Internet style query?
Message
De
25/08/2003 10:04:50
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00823010
Message ID:
00823034
Vues:
23
>Consider a SQL Server table sitting on a Website with say 1,000,000 records. The user on the internet wants to be able to see the first 100 records (sorted by ProductID), then click "Next" and see the next 100 and ... so on.
>How to I write a query to retrieve the nth set of these records.
>ie the query should retrieve the 100*(n-1) to 100*n set of records in the order of field ProductID when the user clicks "Next" for the nth time.

Russell,
ProductIDs are integers, right ? If so you could get top 100 gt last max value retrieved. SQL server optimizes TOP queries well and assuming ProductID is the primary key clustered index would minimize the SQL server i/o. ie:
Local lnHandle
lnHandle=Sqlstringconnect('DRIVER=SQL Server;'+;
   'SERVER=servername;Trusted_connection=Yes;Database=Northwind')
If lnHandle>0
  lnOrderID = 0
* Get reccount
  SQLExec(lnHandle, ;
   "select rows from sysindexes"+;
   " where id=object_id('orders') and indid<2",'crsRecco')
  lnReccount = crsRecco.Rows
  SQLPrepare(lnHandle,"select top 100 * "+;
    "from Northwind.dbo.orders where orderID > ?lnOrderID"+;
    " order by OrderId",'crsResult')
  For ix = 1 To Ceiling(lnReccount/100)
    Wait Window Nowait ;
      Transform((ix-1)*100+1) + ' - ' + ;
      Transform(Min(ix*100,lnReccount)) + ;
      ' of '+Transform(lnReccount)
    SQLExec(lnHandle)
    Browse
    Go Bottom
    lnOrderID = OrderID
  Endfor
  SQLDisconnect(lnHandle)
Endif
Return
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform