How to create a temp table and a table if it not exits only.

How do i create temporary table tempt.
I have to create it in procedure, and everytime, procedure is called the table should be created and old table should be delted.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A sample structure is defined below, This should assist you.

CREATE TABLE #tempTableName
Pratima PharandeCommented:
use this statement before creating tables , replace #tmptable with your tablename

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bhavesh ShahLead AnalysistCommented:
Comments above are good. But your question let me doubt the term 'temp table'.  

In sql server you have temp tables that after your session is finished will be dropped automaticly (so normaly should not exists at next run, except when you do it in query-window without ending the batch), let table start with # (see post before),  with## you get  a global temp table

You can test before you want to create a table if it does not already exists (see higher).
searchsanjaysharmaAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.