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

  • Home
  • SEARCH
  • 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 873395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:55:38+00:00 2026-05-15T10:55:38+00:00

I need a little help writing a query. I have this data… vDir iNumber

  • 0

I need a little help writing a query. I have this data…

vDir    iNumber
North   19
North   27
North   29
North   31
South   46
South   49
South   51
South   61

I need to query the data and have an output something like this

vDir    iLowNumber    iHiNumber
North   19            27
North   27            29
North   29            31
South   46            49
South   49            51
South   51            61

The idea here is to select the direction, the LowNum and then the nextNumber. Also when the direction changes to start over. (That’s why I think I need a Union, maybe get the North, then Union the South). Notice too the highest number in each direction doesn’t create a record because there is no higher number. The first set has 8 records, and the query result is only 6.

How can I create a query that will do this? Also this is a 2008 SQL Database so I can use 2008 TSQL. I’m really curious how to do this in SQL. Thanks guys!

  • 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-15T10:55:39+00:00Added an answer on May 15, 2026 at 10:55 am

    Another possible solution:

    SELECT
        T1.vDir,
        T1.iNumber AS iLowNumber,
        T2.iNumber AS iHiNumber
    FROM
        My_Table T1
    INNER JOIN My_Table T2 ON
        T2.vDir = T1.vDir AND
        T2.iNumber > T1.iNumber
    LEFT OUTER JOIN My_Table T3 ON
        T3.vDir = T1.vDir AND
        T3.iNumber > T1.iNumber AND
        T3.iNumber < T2.iNumber
    WHERE
        T3.vDir IS NULL  -- If this is NULL it means that no rows exist between T1 and T2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.