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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:10:38+00:00 2026-06-11T08:10:38+00:00

IF OBJECT_ID(‘tempdb..#iftry’) IS NOT NULL DROP TABLE #iftry IF OBJECT_ID(‘BIC_Analytics.dbo.AdjudicateAllDCCharteredClaims’) IS NULL begin select

  • 0
IF OBJECT_ID('tempdb..#iftry') IS NOT NULL 
DROP TABLE #iftry

IF OBJECT_ID('BIC_Analytics.dbo.AdjudicateAllDCCharteredClaims') IS  NULL
begin
select 'this is start of first block'
 SELECT 'this is first block' as blockid
 INTO #iftry
select 'this is end of first block'
end

ELSE

begin
select 'this is start of 2nd block'
 SELECT 'this is 2nd block' as blockid
    INTO #iftry
select 'this is end of 2nd block'
end

select ':)'

select * from #iftry

Keeps giving me the error:

Msg 2714, Level 16, State 1, Line 18
There is already an object named '#iftry' in the database.

Now it works

IF OBJECT_ID('tempdb..#iftry') IS NOT NULL 
DROP TABLE #iftry

create table #iftry (blockid varchar(20))


IF OBJECT_ID('BIC_Analytics.dbo.AdjudicateAllDCCharteredClaims') IS NOT NULL
begin
--select 'this is start of first block'
 insert into #iftry (blockid)
 select 'this is first block' 
--select 'this is end of first block'
end

ELSE

begin
--select 'this is start of 2nd block'
 insert into #iftry (blockid)
 select 'this is 2nd block' 
--select 'this is end of 2nd block'
end

select ':)'

select * from #iftry
  • 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-11T08:10:40+00:00Added an answer on June 11, 2026 at 8:10 am

    This is a parsing problem, not a runtime problem. SQL Server can’t see that there are two code paths that can’t be reached.

    To work around it, create your #temp table once up front:

    SELECT 'bogus' INTO #iftry
      WHERE 1 = 0; -- creates empty table
    
    IF ...
      INSERT #iftry ...
    ELSE ...
      INSERT #iftry ...
    

    There’s no way to tell SQL Server not to work this way unless you put the two #table declarations in separate batches (which you can’t really do), or build dynamic SQL and work with the #temp table at that scope (not fun).

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

Sidebar

Related Questions

USE AdventureWorks; GO IF OBJECT_ID (N'dbo.AWBuildVersion', N'U') IS NOT NULL DROP TABLE dbo.AWBuildVersion; GO
Here's some sample code: if object_id('tempdb..#TempList') is not null drop table #TempList create table
I have tried this: if object_id('a_proc22') is not null CREATE PROCEDURE a_proc22 AS SELECT
With the following Stored Procedure in SQL Server 2005 IF OBJECT_ID('[dbo].[UserProfile]') IS NOT NULL
Hi I need help with the syntax on this code: IF OBJECT_ID('TEMPDB..#LTS_MAP') IS NOT
I'm trying to run the following SQL statement: IF OBJECT_ID('MyTable') IS NOT NULL DROP
I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID
I have the following table: if object_id(N'dbo.Node') is null create table dbo.Node ( ID
I have a simple MEDIAN calculation function: IF OBJECT_ID(N'COMPUTEMEDIAN', N'FN') IS NOT NULL DROP
Now I am using something like: IF (object_id('table', 'U') is not null) AND (NOT

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.