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. ROW_NUMBER() problem

ROW_NUMBER() problem

Scheduled Pinned Locked Moved Database
helpquestiondatabasesql-servercom
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.
  • Y Offline
    Y Offline
    Yulianto
    wrote on last edited by
    #1

    When using SELECT ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber] FROM table where RowNumber > 1 It returns error 'Invalid column name 'RowNumber'. What is the problem here? I'm using SQL Server Express 2005. Thanks.


    Don't work hard, but work effectively. Web hosting | invest money | Option strategy

    L 1 Reply Last reply
    0
    • Y Yulianto

      When using SELECT ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber] FROM table where RowNumber > 1 It returns error 'Invalid column name 'RowNumber'. What is the problem here? I'm using SQL Server Express 2005. Thanks.


      Don't work hard, but work effectively. Web hosting | invest money | Option strategy

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You added 'RowNumber' as a column-name alias. Those can be used in the ORDER BY clause, but can't be referenced in the WHERE part. Since you're using SQL 2005, you can bypass this by using a temporary query, selecting into a new CTE first;

      SELECT * FROM
      (
      SELECT ROW_NUMBER() OVER (ORDER BY ID) AS [RowNumber]
      FROM [YourTableNameGoesHere]
      ) AS CTE_TMP
      WHERE [RowNumber] < 10

      Enjoy :)

      I are troll :)

      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