Microsoft SQL Server 2000:Create Row number into select query

Mention TableName and Primary key value in Below Query.

SELECT ( SELECT sum(1) FROM TableName T1
WHERE  T1.PrimartKey <= T2.PrimaryKey
) AS [Row Number]
,*
FROM
TableName T2

Go 

Use of Partition By.

SELECT *
  FROM (
    SELECT  (
      SELECT COUNT(*)
        FROM #temp AS counter
      WHERE counter.meterid = t.meterid --partiton key
        AND  counter.serial >= t.serial--order by key(identity column)
      ) AS rowNumber,*
    FROM #temp t
  ) AS r1

where rownumber between 1 and 10

Comments

Popular posts from this blog

Agent Installation on Windows Server. SQL Server (Failover Cluster) target addition in OEM 12c

Oracle 10g/11g Linux:SMS the alert logs ORA- errors generated in timestamp

Oracle 11g: Install Instant Client 11.2.0.3.0 on Linux x86_64 Server.