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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:38:23+00:00 2026-05-21T22:38:23+00:00

Let suppose my table can have values from 000 to 999 (three digits and

  • 0

Let suppose my table can have values from 000 to 999 (three digits and less than 1000)

Some of this values are filled. Let’s suppose currently my table has

000,002,005,190 (001,004,003,006,..189,191,..,999 can be inserted into table)

and these values are randomly allocated 000 and 002 is in table but 001 is not in table yet.

How can I get the values that I can insert into table yet.

  • 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-21T22:38:24+00:00Added an answer on May 21, 2026 at 10:38 pm
    DECLARE @t TABLE
    (VALUE CHAR(3))
    
    INSERT @t
    VALUES
    ('000'),('002'),('005'),('190')
    
    
    ;WITH rnCTE
    AS
    (
        SELECT -1 + ROW_NUMBER() OVER (ORDER BY TYPE, number, name) AS rn
        FROM master.dbo.spt_values
    )
    SELECT RIGHT('000' + CAST( rn AS VARCHAR(11)),3)
    FROM rnCTE
    WHERE NOT EXISTS    (   SELECT 1 FROM @t 
                            WHERE VALUE = rn
                        )
    AND rn < 1000
    

    EDIT

    This query works by generating the complete list of possible numbers from a system table (master.dbo.spt_values) which is guaranteed to contain more than 1000 rows inside the CTE rnCTE. -1 is added to ROW_NUMBER to have the values start at 0 rather than 1.

    The outer query zero pads the numbers for display, returning only those which are not in the source data and are less than 1000.

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

Sidebar

Related Questions

Let's suppose I have three different select statements, like this SELECT 'Final', ID FROM
Let's suppose we have a table with the fallowing values introduced in this particular
Let us suppose I have a table created as follows: create table `test_table` (
Let's suppose I have all of these already provided: The name of a table
Let's suppose that x is some variable that has any value other than null
Let's suppose I have n arrays, where n is a variable (some number greater
Let's suppose I have a table as such: ID | Date | Owner |
Let's suppose I have the following table (let's call it my_table ): CREATE TABLE
Let's suppose I have this MySQL table: id place_id area_mq n -- -------- -------
Let's suppose I have a table called 'user_products' and a corresponding model called UserProduct

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.