Results 1 to 5 of 5

Thread: [SQL] - Adding Row/Serial Number to Any Database Query

Threaded View

  1. #1

    Thread Starter
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    [SQL] - Adding Row/Serial Number to Any Database Query

    This query will add Serial or Row Numbers 1,2,3...(ascending order) in the result set of any database
    Code:
    SELECT CustCode, CustName, 
    (SELECT COUNT(*) FROM Customers C2 WHERE C2.CustCode <= C.CustCode) AS SrNo
    FROM Customers C
    ORDER BY CustCode
    This will add numbers ....3,2,1 (decending order)
    Code:
    [SELECT CustCode, CustName, 
    (SELECT COUNT(*) FROM Customers C2 WHERE C2.CustCode >= C.CustCode) AS SrNo
    FROM Customers C
    ORDER BY CustCode
    Last edited by ganeshmoorthy; Feb 28th, 2007 at 07:20 AM.
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width