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 7652599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:48:51+00:00 2026-05-31T11:48:51+00:00

I have a sql query below, where dtMontno could start from any month and

  • 0

I have a sql query below, where dtMontno could start from any month and am adding Row column manually as below :

SELECT COUNT(*) as count,
       MONTH(TourTbl.DT_Started) as dtMonthno, 
       DATENAME(YYYY, TourTbl.DT_Started) as dtYear,
       row_number() over (order by DATENAME(YYYY, TourTbl.DT_Started) asc,
                                   MONTH(TourTbl.DT_Started) asc ) as Row 
FROM TourTbl 
INNER JOIN BranchTbl ON TourTbl.BranchID = BranchTbl.BranchID 
INNER JOIN AgencyTbl on AgencyTbl.AgencyID = BranchTbl.AgencyID 
WHERE Cancelled = 0  AND 
      (TourTbl.DT_Started >= '2010/03/15' and 
       TourTbl.DT_Started <= '2012/03/15') AND 
      AgencyTbl.AgencyID in ( 245 ) and 
      BranchRODID > 0
group by datename(M, TourTbl.DT_Started), 
         DATENAME(YYYY, TourTbl.DT_Started), 
         MONTH(TourTbl.DT_Started) 
order by dtYear asc, dtMonthno asc 

now my result is :

  count dtMonthno dtYear    Row
    6      5      2011      1
    8      6      2011      2
    2      7      2011      3
    23     8      2011      4
    126    9      2011      5
    101    10     2011      6
    85     11     2011      7
    92     12     2011      8
    115    1      2012      9
    102    2      2012      10
    48     3      2012      11

Is there any way to start the Row column depending on the dtMonthno and increment by one in the example above would start from 5 and end in 15?

Thanks

  • 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-31T11:48:53+00:00Added an answer on May 31, 2026 at 11:48 am

    Try changing the derivation of Row to:

    row_number() over (order by YEAR(TourTbl.DT_Started) asc,
                                MONTH(TourTbl.DT_Started) asc ) +
    min(YEAR(TourTbl.DT_Started)*12+MONTH(TourTbl.DT_Started)-1) OVER () % 12 as Row 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below SQL query: SELECT * FROM ( SELECT S.aCol, S.bCol, S.cCol, ROW_NUMBER()
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',
I have the below sql query to insert the records from a table. The
I have the SQL query: SELECT ISNULL(t.column1, t.column2) as [result] FROM t I need
I have a SQL Query as below: SELECT urban_appr, urban_in, rural_appr, rural_in, ground_appr, ground_in
Consider the SQL query below: SELECT * FROM opening_hours WHERE week_day = WEEKDAY(NOW()) +
i have a sql query in asp.net SqlCommand QueidCmd = new SqlCommand(select scope_identity() from
I have an SQL query: SELECT ShipVia, SUM(Freight) FROM Orders GROUP BY ShipVia which
I have the below SQL query: SELECT g.name AS gname, COUNT(u.id) AS noMembers, f.name

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.