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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:10:06+00:00 2026-05-28T14:10:06+00:00

To retrieve values which are not in db, I use Common Table Expression like

  • 0

To retrieve values which are not in db, I use Common Table Expression like this :

;WITH new_id (id) AS (
  SELECT '0x01'
  UNION ALL SELECT '0x00'
  UNION ALL SELECT '0x03'
  UNION ALL SELECT '0x04'
  UNION ALL SELECT '0x05'
)

SELECT  id AS p
FROM   new_id ni EXCEPT(SELECT id FROM table)

Is this an optimized way to retrieve values which are not stored in DB ?

Kind regards,

Florian

  • 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-28T14:10:07+00:00Added an answer on May 28, 2026 at 2:10 pm

    That should be fine.

    For a large number of rows (especially if they contain long string values) I have noticed that these internal tables of constants can take a long time to compile but I doubt you will hit this issue for 30 rows.

    From a quick test this end they have an advantage over table variables as SQL Server seems to maintain some statistical information about them so can choose an appropriate join type.

    I just tried a CTE with 500 rows and 50 distinct values and the estimated number of rows in the plan below was correct. (though it is a bit of a shame that having worked all this stuff out at compile time and presumably having generated a distinct list of ids for that purpose that SQL Server doesn’t just substitute that into the plan instead of having to do it again at run time)

    Plan

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

Sidebar

Related Questions

So basically, I have this content provider which I use to store and retrieve
I would like to retrieve at runtime the values for the dialect and connection.driver_class
When I retrieve the cookies in my java servlet, all of the values from
I am using this code to retrieve the values I want from XML: IEnumerable<ForewordReview>
i have a function which retrieves values from a webservice , then loops through
I'm trying to retrieve mulitple checked value, which are being showed in JSP dynamically,
I'm using CF to retrieve values from a database that are then being stored
Is there any way to retrieve relevance values with results with the array returned
I'm having a headache figuring how to retrieve the gwt Radio Buttons values in
I'm doing some manipulation and retrieval of values stored in a table. Each row

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.