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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:48:29+00:00 2026-05-13T00:48:29+00:00

I hope you can understand my question, if not, please let me know… In

  • 0

I hope you can understand my question, if not, please let me know…

In my form I have eight textboxes, like so (user wrote ’25’ to first textbox and ’35’ to second one):

Code1From: _25____   Code1To:_35____
Code2From: _______   Code2To:_______
Code3From: _______   Code3To:_______
Code4From: _______   Code4To:_______

My table looks like this:

create table MyTable (
    Id int identity(1,1),
    Code1From bigint, Code1To bigint,
    Code2From bigint, Code2To bigint,
    Code3From bigint, Code3To bigint,
    Code4From bigint, Code4To bigint
)

Now I’d like to prevent inserting data, that is allready inserted. For example:
Data in MyTable:

Id, Code1From, Code1To, Code2From, Code2To, Code3From, Code3To, Code4From, Code4To
1, 1, 10, null, null, null, null, null, null
2, 11, 20, null, null, null, null, null, null
3, 21, 30, null, null, null, null, null, null
4, 31, 40, null, null, null, null, null, null
5, 41, 50, null, null, null, null, null, null

If user wants to insert for Code1 (or Code2, Code3 or Code4) from 25 to 35, I should raise an error
(because span from 25 to 35 is allready in the database – id 3 and 4).
However, user can insert span from 51 to 55 for example.

How can I determine, if a span is allready in my database? Now I could do something like this:

select *
from MyTable
where
   @code1From between Code1From and Code1To
or @code1From between Code2From and Code2To
or @code1From between Code3From and Code3To
or @code1From between Code4From and Code4To
--
or @code1To between Code1From and Code1To
or @code1To between Code2From and Code2To
or @code1To between Code3From and Code3To
or @code1To between Code4From and Code4To
--
... and another 24 or statements

Is there any easier way to accomplish this?

  • 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-13T00:48:30+00:00Added an answer on May 13, 2026 at 12:48 am

    If i understand you correctly, this might help you

    DECLARE @Table TABLE(
            FromVal1 FLOAT,
            ToVal1 FLOAT,
            FromVal2 FLOAT,
            ToVal2 FLOAT,
            FromVal3 FLOAT,
            ToVal3 FLOAT,
            FromVal4 FLOAT,
            ToVal4 FLOAT
    )
    
    INSERT INTO @Table (FromVal1,ToVal1,FromVal2,ToVal2) SELECT 1, 10, 51, 60
    INSERT INTO @Table (FromVal2,ToVal2) SELECT 11, 20
    INSERT INTO @Table (FromVal3,ToVal3) SELECT 21, 30
    INSERT INTO @Table (FromVal4,ToVal4) SELECT 31, 40
    INSERT INTO @Table (FromVal1,ToVal1) SELECT 41, 50
    
    DECLARE @FromVal FLOAT,
            @ToVal FLOAT
    
    SELECT  @FromVal = 25,
            @ToVal = 35
    
    SELECT  *
    FROM    @Table
    WHERE   NOT(FromVal1 > @ToVal OR ToVal1 < @FromVal)
    OR      NOT(FromVal2 > @ToVal OR ToVal2 < @FromVal)
    OR      NOT(FromVal3 > @ToVal OR ToVal3 < @FromVal)
    OR      NOT(FromVal4 > @ToVal OR ToVal4 < @FromVal)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure if the title makes sense, but I hope you can understand
I have some basic git questions, which i do not understand yet I hope
I hope I can explain this well enough so that you can understand the
I hope you can help, I've tried for hours to understand mod rewrite but
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
I gotta a question, but not sure if I understand it right so here
Hope somebody can help. Have looked around on the net but cannot seem to
I have really simple and lame question (i hope it's simple). I'm quite new
I'm going to preface with: I hope I can ask this question here, because
hope someone can answer this. Here is some sample code. namespace std { #ifdef

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.