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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:08:54+00:00 2026-06-16T14:08:54+00:00

I have an SQL table including two columns depicting a range of IDs; those

  • 0

I have an SQL table including two columns depicting a range of IDs; those ranges needs to be compared with a cell under a particular ID column in a second table – if it is within the range, inclusively, the row of the second table will be included in the return.

Edit: The ranges available are limited by a range of user-supplied dates.

I’m only familiar with the basics of SQL; before I start researching loops and predefined tabular functions, does anyone have any suggestions?

SELECT * FROM [ADataBase].[dbo].[AFirstTable]
  WHERE [ALongIDNumber] <=
     (SELECT [StartOfIDRange] FROM [DHL].[dbo].[ASecondTable]
     WHERE [date] BETWEEN '2010-01-21' AND '2010-01-22')
  AND   [ALongIDNumber] >=
     (SELECT [EndOfIDRange] FROM [DHL].[dbo].[ASecondTable]
      WHERE [date] BETWEEN '2010-01-21' AND '2010-01-22')

Currently, this returns the error
Msg 512, Level 16, State 1, Line 2
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Which I’m guessing is causing it to fluff up because there’s several rows returned by the selects.

I’ve researched, and come across a similar question of which the only answers are for fixed number of ranges. Because I query a table for the ranges, the number of ranges will change.

Due to the nature of this scenario, modifying the databases is a last resort.

Thanks for your help!

  • 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-06-16T14:08:56+00:00Added an answer on June 16, 2026 at 2:08 pm

    I’m really unclear from your narrative, but I think that what you might be looking for is the concept of a Join:

    SELECT * FROM
       [ADataBase].[dbo].[AFirstTable] first
           inner join
       [DHL].[dbo].[ASecondTable] second
           on
              first.[ALongIDNumber] between second.[StartOfIDRange] and second.[EndOfIDRange]
    WHERE
       second.[date] BETWEEN '20100121' AND '20100122'
    

    This will find rows in first that fit into any range of ID values that occurs as a single row in second. This does mean that if there are overlapping ranges of ID values in second, you might receive multiple rows in the result set, for a single original row in first.

    before I start researching loops…

    Don’t. Although there are some crude ways to perform looping in SQL, you really shouldn’t go there. The idea behind SQL is you describe what result you want, and the SQL engine works out the best way to achieve that (whether that be, behind the scenes, looping, creating hash tables, spilling items to disk, etc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL table in which some columns, when viewed in SQL Server
I have a SQL table tablex with 3 columns(A, B ,C ). The following
I have two columns in a table that need to be added together. One
I have a SQL table with periodic measurements. I'd like to be able to
I have an sql table containing the gps coordinates of a device, updated every
I have a SQL table BookChapters with over 20 millions rows. It has a
I have a SQL table with following fields ID, Rly, Shed, Loco_no, shed, Date_failure,
I have a SQL table that has a primary key ( Row_id ) that
I have an SQL table written in MSSQL: create table [action] ( action_id bigint
I have a SQL table where in each row I store the country and

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.