Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 using IF ELSE with temp table

Author  Topic 

sahu74
Posting Yak Master

100 Posts

Posted - 2003-10-31 : 10:39:11
Hi,
I am trying to execute a stored procedure with the following format. I am getting an error :
"There is already an object named '#BSBF' in the database."

Could you please suggest where I am messing up?

Thank you.
PKS.


DECLARE @DIV as varchar(10)
DECLARE @SUBDIV as varchar(10)

SET @DIV = 'YA'
SET @SUBDIV = 'ZYASA'

IF @DIV = ''
BEGIN

SELECT ........
INTO #BSBF
FROM ........
WHERE SubDivisionID LIKE @SubDiv

DROP TABLE [#BSBF]

END

ELSE

IF @DIV <>''
BEGIN

SELECT ......
INTO #BSBF
FROM ......
WHERE DivisionID LIKE @Div

DROP TABLE [#BSBF]

END

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2003-10-31 : 10:44:46
You can try creating your #BSBF table prior to condition test and then insert into #BSBF rather than select into
Go to Top of Page

sahu74
Posting Yak Master

100 Posts

Posted - 2003-10-31 : 10:50:42
I will give that a try... But what should be the logic for the existing code not to work?
PKS.

quote:
Originally posted by ehorn

You can try creating your #BSBF table prior to condition test and then insert into #BSBF rather than select into

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-10-31 : 11:53:24
You have redundancies in your code:

IF DIV = '' xxx
ELSE IF DIV <> '' xxx

should be simply:

IF DIV = '' xxx ELSE xxxx

- Jeff
Go to Top of Page
   

- Advertisement -