Link to home
Start Free TrialLog in
Avatar of bhummel
bhummel

asked on

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
Avatar of vvk
vvk

Does your script working fine when you start it from isqlw window?
ASKER CERTIFIED SOLUTION
Avatar of mvz121697
mvz121697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhummel

ASKER

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
With DROP TABLE you remove the whole table structure !
To remove only the records, just do:

DELETE FROM Table_Name


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.

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.