Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. A Transact-SQL Question

A Transact-SQL Question

Scheduled Pinned Locked Moved Database
databasehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xiaoming Qian
    wrote on last edited by
    #1

    I have a WebForm that will display paging data to customers.My purpose is to let the customers can select any page number.The WebForm calls a stored procedure in SQL2000: ALTER PROCEDURE MyProc (@RecordPerPage int, @PageNumber int ) AS select top @RecordPerPage * from MyTable where KeyField> select Max(KeyField) from (select top @RecordPerPage*(@PageNumber-1) KeyField from MyTable order by KeyField) a order by KeyField Unfortunately,this procedure has a syntax error.It seems that the 'TOP' keyword can not be followed by an Expression. How could I do? I do not want to dynamicaly generate SQL string in client side(there are a dozen of reasons) and -- This is a large table,I will not use DataAdapter.Fill and DataGrid.AllowPaging. Need your help! Thanks a lot!

    G 1 Reply Last reply
    0
    • X Xiaoming Qian

      I have a WebForm that will display paging data to customers.My purpose is to let the customers can select any page number.The WebForm calls a stored procedure in SQL2000: ALTER PROCEDURE MyProc (@RecordPerPage int, @PageNumber int ) AS select top @RecordPerPage * from MyTable where KeyField> select Max(KeyField) from (select top @RecordPerPage*(@PageNumber-1) KeyField from MyTable order by KeyField) a order by KeyField Unfortunately,this procedure has a syntax error.It seems that the 'TOP' keyword can not be followed by an Expression. How could I do? I do not want to dynamicaly generate SQL string in client side(there are a dozen of reasons) and -- This is a large table,I will not use DataAdapter.Fill and DataGrid.AllowPaging. Need your help! Thanks a lot!

      G Offline
      G Offline
      Grav Vt
      wrote on last edited by
      #2

      You should build your SQL statement as a nvarchar and then use sp_executesql: DECLARE @query NVARCHAR(500) SET @query = N'select top ' + CAST(@RecordPerPage AS NVARCHAR(5)) + N'* from MyTable... sp_executesql @query look at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts\_sp\_ea-ez\_2h7w.asp --> Nick

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups