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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:36:49+00:00 2026-06-11T19:36:49+00:00

I have searched and found nothing about it (I believe it is impossible to

  • 0

I have searched and found nothing about it (I believe it is impossible to do it). My problem is that I have to check if a temporary table exists and also if there is some specific data on that temporary table.

Did anyone faced this before? How did you managed to solve it? I would like to avoid creating milions of IF..ELSE blocks.

EDIT:

IF (OBJECT_ID('tempdb..#tempTable') IS NOT NULL 
AND EXISTS (SELECT * FROM #tempTable WHERE THIS_COLUMN = 'value'))
BEGIN
   PRINT 'Temp table and data exists'
END
ELSE
BEGIN
   PRINT 'Temp table or data does not exist'
END

This is what I want to do. The problem comes when the tempTable doesn’t exist (that could happen). It throws an error because, although the first stamement returns false, it continues to execute the second statement. And the SELECT statement is not able to find the table and therefore throws the error. The solution I found was to do this:

IF OBJECT_ID('#tempTable') IS NOT NULL
BEGIN
    IF EXISTS (SELECT * FROM #tempTable WHERE THIS_COLUMN = 'value'
    BEGIN
        PRINT 'Temp table and data exists'
    END
    ELSE
    BEGIN
        PRINT 'Temp table exists but data does not exist'
    END
END
ELSE
BEGIN
    PRINT 'Temp table does not exist'
END

My question would be, is there a way of having 2 conditions and if the first condition returns false not check the second one? Kind of using && in a programming language.

  • 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-11T19:36:50+00:00Added an answer on June 11, 2026 at 7:36 pm

    What you are trying to do is not possible as this is a compile time failure and the whole statement needs to be compiled together.

    It won’t evaluate the first part of the statement then compile the second part only if that is true. You need to split the test for existence and the query referencing the table into two separate statements so they are compiled separately.

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

Sidebar

Related Questions

I have searched for a CGI and read about it but nothing useful found.
I have searched and nothing that I have found hits directly on what I
I have searched in google about mongoDB and iOS but found nothing. Can I
I have searched on internet about implementation of Segment trees but found nothing when
I have searched on this problem, but have found nothing. I have triple checked
I have searched for similar issues but I found nothing... I have a problem
I have searched and found that in cordova.plist we need to add a row
I have searched and found a lot of different things but none that actually
I have searched for hours now and haven't found a solution for my problem.
i have searched Xcode controls but doesn't found anything that makes a GridView like

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.