Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error 2714 when parsing stored procedure

Posted on 2004-08-02
8
Medium Priority
?
509 Views
Last Modified: 2008-02-01
I have stored procedure with several IF statements. In each IF I use SELECT .. INTO #temp but I get error 2714 (table already exists).
It is not true becouse only one IF will be run.

What can I do?
0
Comment
Question by:patrikt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 11692343
Try Drop the temp table 1st if it's exist, like:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[YourTableName]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[YourTableName]

...
0
 
LVL 12

Author Comment

by:patrikt
ID: 11692388
No way. Table does'not exests. I put drop before all selects but still have error.

It's only parsing error. It should work correctly when run.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 11692417
Can you post full scripts here?
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 5

Accepted Solution

by:
hkamal earned 750 total points
ID: 11693002
I had this and it is very frustrating. The best option :
1. If you're selecting the same columns, create the table upfront and use INSERT .. SELECT instead
2. If you're selecting out different columns/tables depending on the IF, use Dynamic SQL to create the table name; viz:
SELECT @sql="select * into #temptab from TableA"
EXEC (@sql)
Since Sybase doesn't see the select into at compile time, you avoid the error
0
 
LVL 5

Expert Comment

by:hkamal
ID: 11693013
I said Sybase when I meant SQL SERVER !
Works for both actually
0
 
LVL 7

Expert Comment

by:FDzjuba
ID: 11695127
after you have created temp table, don't forget to drop at the end of the sp, and before you start sp check that none of the temp tables exist and if they do drop them:

if object_id('#temp') is not null
begin
   drop table #temp
end
0
 
LVL 2

Expert Comment

by:nexusSam
ID: 11695304
FDzjuba, neither is necessary.
SQL appends the session ID to the temp table name (hence the 11-char name limit compared with 32 for permenant tables).
They are automatically destroyed when you exit a proc in which they were created.
As for checking for their existence, I wouls simply use a new name.
0
 
LVL 12

Author Comment

by:patrikt
ID: 11695412
Hkamal is right.

It it realy bug of parser. Parser hates "double" creating temp table in different branches of IF.
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question