Solved

Create Table Problem

Posted on 1998-08-19
6
192 Views
Last Modified: 2010-03-19
Greetings,
I am trying to create a table using using a sp_ and the following code:

CREATE TABLE Summary_Tbl
(Criimi             varchar(6),
PropertyNBR             int,
Report_Period            datetime,
ChartofAccount_Code      varchar(5),
Revenue                  money,
Expenses            money,
Excluded            money)

The sp seems to work fine (i.e., no errors) but the table is never created. I get an Invalid Object Name error later when I try to merging a number of temp tables into Summary_Tbl.

What's up? Besides the sky....

Thanks,
Brad
0
Comment
Question by:bhummel
[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
6 Comments
 
LVL 4

Expert Comment

by:vvk
ID: 1089631
Does your script working fine when you start it from isqlw window?
0
 
LVL 2

Accepted Solution

by:
mvz121697 earned 100 total points
ID: 1089632
You can only create temporary tables from within a stored proc.
They are created in database tempdb and are only there as long as your sp runs.
0
 

Author Comment

by:bhummel
ID: 1089633
I found that out last night. So, I created the table using enterprise manager. What I want to do is keep the same table but remove the records (I though "DROP TABLE" would do this) but now when I reference the table I get:
Invalid object name 'Statement_Summary_Tbl'
when I try to INSERT INTO 'Statement_Summary_Tbl'

Is there a better way to remove all the records each time the sp is executed?

FYI- vvk I am now doing all of this in Isql.

Thanks,
Brad
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 2

Expert Comment

by:mvz121697
ID: 1089634
With DROP TABLE you remove the whole table structure !
To remove only the records, just do:

DELETE FROM Table_Name


0
 
LVL 2

Expert Comment

by:mvz121697
ID: 1089635
bhummel,

A correction to my first answer,
It _is_ possible to create a table from within a stored proc.
(At least with SQL-Server 6.5)

I think your DROP TABLE command was your problem in the first place.
This command does totally remove the table.

0
 
LVL 2

Expert Comment

by:formula
ID: 1089636
Within a stored procedure, I use TRUNCATE TABLE to keep the table structure and get rid of the records.  It's faster than
DELETE because it does not log individual row deletions.  If you
table doesn't contain rows you want to keep permanently, its the way to go.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

734 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