Invalid Object Name

I have a function here that gives me the error: "Invalid Object Name: 'dbo.leadPerformance' " around the function name.

I'm not too sure what is wrong here.

ALTER FUNCTION [dbo].[leadPerformance]
(	
@startDate	datetime,
@endDate	datetime
)
RETURNS TABLE 
AS
RETURN 
(
	SELECT USERID, USERNAME,CREATEDATE
	from sysdba.USERINFO
	WHERE CREATEDATE > @startDate
	and CREATEDATE <@endDate
)

July 6th, 2015 3:41pm

Do you have access to alter the function?
Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 3:49pm

I have a function here that gives me the error: "Invalid Object Name: 'dbo.leadPerformance' " around the function name.

I'm not too sure what is wrong here.

ALTER FUNCTION [dbo].[leadPerformance]
(	
@startDate	datetime,
@endDate	datetime
)
RETURNS TABLE 
AS
RETURN 
(
	SELECT USERID, USERNAME,CREATEDATE
	from sysdba.USERINFO
	WHERE CREATEDATE > @startDate
	and CREATEDATE <@endDate
)

I'd check two things:

  1. You are in the correct database when running the script.
  2. The database does / does not have case sensitive collation.
SELECT name, collation_name 
FROM sys.databases

SELECT name, type, schema_name(schema_id) as [schema] 
FROM sys.objects 
WHERE name = 'leadPerformance'
You can add a USE statement to the script to make sure you're in the right place. The query above should show you if the object exists...

I hope you found this helpful! If you did, please vote it as helpful on the left. If it answered your question, please mark it as the answer below. :)



July 6th, 2015 3:53pm

You need to connect to the right database where this function exists.
Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 3:59pm

Thank you for your response. I am in the correct DB and also use the 'USE [DB_NAME]' statement at the beginning of my function. The issue is that error shows up even when I try to alter the function.

I ran the second statement and get the following:

Name: leadPerformance

type: IF

schema:dbo

When I run:
select * from sysdba.leadPerformance('Jan 1, 2015','Jan 1, 2016') it outputs correctly although line sysdba.leadPerformance is red.

Maybe it needs to register something in the backend to work and that takes time?

July 6th, 2015 5:07pm

Maybe it needs to register something in the backend to work and that takes time?

Nothing needs to refresh. You can refresh your intellisence cache with CTRL-SHIFT-R.

What happens when you try:

CREATE FUNCTION [dbo].[leadPerformance]
(	
@startDate	datetime,
@endDate	datetime
)
RETURNS TABLE 
AS
RETURN 
(
	SELECT USERID, USERNAME,CREATEDATE
	from sysdba.USERINFO
	WHERE CREATEDATE > @startDate
	and CREATEDATE <@endDate
)
GO

ALTER FUNCTION [dbo].[leadPerformance]
(	
@startDate	datetime,
@endDate	datetime
)
RETURNS TABLE 
AS
RETURN 
(
	SELECT USERID, USERNAME,CREATEDATE
	from sysdba.USERINFO
	WHERE CREATEDATE > @startDate
	and CREATEDATE <@endDate
)
GO

I hope you found this helpful! If you did, please vote it as helpful on the left. If it answered your question, please mark it as the answer below. :)

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2015 5:24pm

I ran the second statement and get the following:

Name: leadPerformance

type: IF

schema:dbo

When I run:
select * from sysdba.leadPerformance('Jan 1, 2015','Jan 1, 2016') it outputs correctly although line sysdba.leadPerformance is red.

This sounds spooky. What if you run DBCC CHECKCATALOG? Does it report anything?

July 6th, 2015 6:56pm

Hi,

Check for the permissions on the function object and whether you have the right permissions or not.

Below is something that can help you out.

You must have been granted CREATE FUNCTION permissions to create, alter, or drop user-defined functions. Users other than the owner must be granted EXECUTE permission on a function (if the function is scalar-valued) before they can use it in a Transact-SQL statement. If the function is table-valued, the user must have SELECT permissions on the function before referencing it. If a CREATE TABLE or ALTER TABLE statement references a user-defined function in a CHECK constraint, a DEFAULT clause, or a computed column, the table owner must also own the function. If the function is being schema-bound, you must have REFERENCE permission on tables, views, and functions referenced by the function.

Please mark as answer if this post solved your problem.

Regards,

Milan

Free Windows Admin Tool Kit Click here and download it now
July 7th, 2015 1:53am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics