Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4338324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:03:59+00:00 2026-05-21T11:03:59+00:00

I am trying to obtain a sequential row numbering, but whatever I am trying

  • 0

I am trying to obtain a sequential row numbering, but whatever I am trying is not working. Here is my query

select
    l.seq, l.mn_no as mn_no, l.sb_no as sb_no,
    l.dp_no as dp_no,
    sum(costprice) as amt
from 
    dbo.mac_pur_tempdetail d
inner join 
    dbo.mac_pur_tempheader h on d.header_id = h.header_id
                              and h.ref = 'SAH1FIHC'
inner join 
    dbo.mac_actlocmap l on l.loc_main = d.loc_id
                         and l.description = 'PUR'
group by  
    l.seq, l.mn_no, l.sb_no, l.dp_no

Here is the result of that query

1   4110        30          0000        17.5000
4   4110        20          0000        3.6000
6   4110        40          0000        6.0000
7   4110        10          0000        1.8000
14  4110        25          0000        3.6000
15  4110        50          0000        1.8000

I tried

select
    (select count(seq)  
     from dbo.mac_actlocmap s
     where s.seq <= a.seq and a.mn_no = s.mn_no) as new_seq,
    * 
from 
    (select
         l.seq, l.mn_no as mn_no,
         l.sb_no as sb_no, l.dp_no as dp_no,
         sum(costprice) as amt
     from 
         dbo.mac_pur_tempdetail d
     inner join 
         dbo.mac_pur_tempheader h on d.header_id = h.header_id
                                  and h.ref = 'SAH1FIHC'
     inner join 
         dbo.mac_actlocmap l on l.loc_main = d.loc_id
                              and l.description = 'PUR'
     group by  
         l.seq, l.mn_no, l.sb_no, l.dp_no) a

But the result is

1   1   4110        30          0000        17.5000
2   4   4110        20          0000        3.6000
3   6   4110        40          0000        6.0000
4   7   4110        10          0000        1.8000
7   14  4110        25          0000        3.6000
8   15  4110        50          0000        1.8000
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:04:00+00:00Added an answer on May 21, 2026 at 11:04 am

    Your count is counting unaggregated and unfiltered rows in dbo.mac_actlocmap. But you are comparing to a subquery with an aggregate and filter.

    With this complexity, use a temp table. It’s just easier than having exactly the same query twice for the triangular join needed to emulate ROW_NUMBER on SQL Server 2000

    select
    l.seq,
    l.mn_no as mn_no,
    l.sb_no as sb_no,
    l.dp_no as dp_no,
    sum(costprice) as amt
    
    INTO #foo
    
    from dbo.mac_pur_tempdetail d
    inner join dbo.mac_pur_tempheader h
    on d.header_id = h.header_id
    and h.ref = 'SAH1FIHC'
    inner join dbo.mac_actlocmap l
    on l.loc_main = d.loc_id
    and l.description = 'PUR'
    group by  l.seq,l.mn_no,l.sb_no,l.dp_no
    
    select
    (select count(seq) from #foo s
    where s.seq <= a.seq and a.mn_no = s.mn_no) as new_seq,
    * from #foo a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a MySQL query which will obtain the time that is
I am trying to obtain something similar to the share this on... menu here
I am trying to obtain html from the WebBrowser control, but it must include
I am trying to obtain the document inside a frame. The following does not
I'm trying to obtain an instance of ServiceState in my Activity . But how
I am trying to obtain column sums & row sums by aggregating with previous
I'm trying to obtain the camera rotation on various axis in OpenGL (but using
I'm trying to obtain my local (not the external) IP address using the getaddrinfo()
I am trying to obtain the list of files matching a full-path pattern. So
I'm trying to obtain and save a stack trace to a file after I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.