Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this procedure that should import a excel file Using a job and then I have some queries that create some report and after all it export the reports.

But when I execute the procedure The Job Works correctly and it import the excel file but the rest of the codes won't recognize the table that just imported and SQL gives me this error:


Job 'IMP' started successfully.

Msg 208, Level 16, State 1, Procedure Final_Result, Line 7 Invalid object name 'dbo.'New LP''.

(1 row(s) affected)

but when I Refresh the SQL database the table 'New LP' exist. how should I fix this Problem?

What I have tried:

the only way that it works is that I import the file at the first and execute the queries afterward.
But I need to have the import and export in the same stored procedure.
What should I do?
Posted
Updated 21-Sep-16 6:37am
Comments
Karthik_Mahalingam 21-Sep-16 12:01pm    
check this object exists in db
dbo.'New LP'

Given that you haven't provided a sample sql query you are running, I'm going to say it is because you are trying to query out of it by saying

SELECT * FROM dbo.New LP


When instead you need to be using something like

SELECT * FROM dbo.[New LP]


Sql server doesn't like spaces in table names, so when this happens you need to use the brackets like i've shown to query a table with a space in the name.

To replicate, do something like this

CREATE TABLE [Test Data]
(
	Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
	Name VARCHAR(20)
) 


SELECT * FROM [dbo].[Test Data]
SELECT * FROM Test Data


You'll see the first query works but the second does not.
 
Share this answer
 
v2
Comments
Member 11873237 21-Sep-16 9:56am    
this is exactly what I have in my query:from [dbo].['New LP']
[no name] 21-Sep-16 10:00am    
Are you sure that your table name is ['New LP'] and not just [New LP]? Try losing the single quotes characters.
Member 11873237 21-Sep-16 10:17am    
Yes it is exactly the one. cause I drag the database inside the code and it paste it itself.
[no name] 21-Sep-16 11:26am    
So in other word, you aren't sure at all. Look at the database in SSMS and see for sure.
Quote:
Line 7 Invalid object name 'dbo.'New LP'

An error message is quite clear!

Check the name of object and correct it. Enclose the name of object in square-brackets if the name of object contains a space: dbo.[New LP]

For further information, please see: Microsoft – SQL Server – Transact SQL – “Invalid Object”[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900