create procedure proc1 (@a int)
as
begin
if @a=1
create table #temp(a1 int)
else
create table #temp(a1 int)
end

while executeing the above code it shows error
like '#temp already exist' .why it shows an error?

Answer Posted / soorai ganesh

Problem in #temp table. Because it comes twice in SP.
(U can say it is in else part. But compiler will not accept
this.First it will compile everthing then running the SP. )

Its better to keep another name for Else part table.......

Is This Answer Correct ?    8 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write down the syntax and an example for create, rename and delete index?

530


Benefits of Stored Procedures?

565


What are entities and relationships?

550


What are the restrictions while creating batches in sql server?

583


Give a example to search fr a string in all stored procedure in sql server.

532






How to return the second 5 rows in ms sql server?

630


What is a data collection table?

540


What is the difference between deallocate cursor and close cursor?

714


what is denormalization? : Sql server database administration

471


Where is my database stored on the hard disk in ms sql server?

590


What is a derived table?

509


How to optimize stored procedures in sql server?

624


can an automatic recovery be initiated by a user? : Sql server administration

516


What is the difference in accessing db between sql server vs sql azure?

157


Why does sql studio use a single registered database repository? : sql server management studio

526