• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Create Table Problem

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
bhummel
Asked:
bhummel
1 Solution
 
vvkCommented:
Does your script working fine when you start it from isqlw window?
0
 
mvz121697Commented:
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
 
bhummelAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
mvz121697Commented:
With DROP TABLE you remove the whole table structure !
To remove only the records, just do:

DELETE FROM Table_Name


0
 
mvz121697Commented:
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
 
formulaCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now