Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

SQL - Ambil data berdasarkan halaman

Coba yang ini -

CREATE PROCEDURE [dbo].[GetAllContacts] 
(
      @searchVal VARCHAR(500)
    , @from INT
    , @row_count INT = 20
)
AS
BEGIN

    SELECT DISTINCT (Id) AS Id
                ,   FirstName
                ,   LastName
                ,   address
                ,   Tel_no
    FROM tblContact
    WHERE FirstName LIKE '%' + @searchVal + '%'
        OR LastName LIKE '%' + @searchVal + '%'
    ORDER BY LastName
        OFFSET @from ROWS
        FETCH NEXT @row_count ROWS ONLY;

END

Contoh -

EXEC GetAllContacts @searchVal = ''
    ,   @from = 0
    ,   @row_count = 20

EXEC GetAllContacts @searchVal = ''
    ,   @from = 20
    ,   @row_count = 20

EXEC GetAllContacts @searchVal = ''
    ,   @from = 40
    ,   @row_count = 20


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Hirarki di SQL server 2005 dengan XML

  2. Cara termudah untuk menemukan IsManager di SQL

  3. Hasil kursor tidak konsisten saat mengulang database

  4. Perilaku Rencana Kueri Tabel Temporal SQL Server 2016

  5. kueri server sql berjalan lambat dari java