locked
Msg 4121, Cannot find either column "dbo" or the user-defined function or aggregate, or the name is ambiguous. RRS feed

  • Question

  • User30537209 posted

    Hi.

    I know this error has been posted before in a similar thread, but my situation is different.

    I have this View:

    ALTER VIEW [dbo].[ViewGradeStatisticsDetailed]
    AS
    SELECT
    	D.DERS_KR,
    	D.OFF_DEPT,
    	D.DERS_KODU,
    	D.DERS_YILI,
    	D.SOM,
    	D.GRUP,
    	dbo.GetStudentCountWithoutNG_W(D.DERS_KODU,D.GRUP,D.DERS_YILI,D.SOM) StudentCount,
    	dbo.GetLetterGradeStatCount(D.DERS_KODU,D.GRUP,D.DERS_YILI,D.SOM,'A') [A#]
    
    FROM DERSLER D
    WHERE D.DERS_KR>0

    And this is the function dbo.GetStudentCountWithoutNG_W

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER FUNCTION [dbo].[GetStudentCountWithoutNG_W]
    	(  @CourseCode nvarchar(7),@CourseGroup nvarchar(2),@CourseYear nvarchar(7),@CourseSemester nvarchar(1))
    	RETURNS int
    	as
    	BEGIN 
    		DECLARE @returnValue int 
    		SELECT @returnValue = count( DERS_NOT )
    		FROM NOTLAR N
    		WHERE 
    			N.DERS_KOD=@CourseCode AND 
    			N.GRUP= @CourseGroup AND
    			N.DERS_YILI = @CourseYear AND
    			N.SOM = @CourseSemester AND
    			N.SOM1 = '1' AND
    			N.DERS_NOT != 'NG' AND
    			N.DERS_NOT != 'W'
    		RETURN (@returnValue)
    	END

    The function by itself works fine, but when I try to Select data from the View it gives me this error:

    Msg 4121, Level 16, State 1, Line 1
    Cannot find either column "dbo" or the user-defined function or aggregate "dbo.GetStudentCount", or the name is ambiguous.

    Both view and function are under the same database. Why do I get this error while the function names match completely?

    Note that the error mentions dbo.GetStudentCount while this was the old name of the function which I renamed later to dbo.GetStudentCountWithoutNG_W

    What do you suggest?

    Tuesday, March 6, 2012 4:29 AM

Answers

  • User30537209 posted

    Oh my God,

    It is not the dbo.GetStudentCountWithoutNG_W that is causing the problem, but it is dbo.GetLetterGradeStatCount!

    I have used dbo.GetStudentCount inside dbo.GetLetterGradeStatCount and since it was renamed it was causing the error. The mssql wasn't telling me that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 6, 2012 5:19 AM

All replies

  • User-1360095595 posted
    Try removing dbo. And call the function by it's name only. Alternatively, try using [dbo].[blahblah]
    Tuesday, March 6, 2012 4:35 AM
  • User30537209 posted

    It doesn't work,

     

    here are the different tries:

    dbo.[GetStudentCountWithoutNG_W]
    
    [dbo].[GetStudentCountWithoutNG_W]
    
    [GetStudentCountWithoutNG_W] // This one gives the error: Incorrect syntax near '('.
    
    GetStudentCountWithoutNG_W // This one gives the error: 'GetStudentCountWithoutNG_W' is not a recognized built-in function name.

     

    None of them worked. I restarted the sql server to make sure nothing's wrong with that.

    And this happened after I renamed the GetStudentCount to GetStudentCountWithoutNG_W.

    Why doesn't this happen to other functions I use?

    Tuesday, March 6, 2012 4:59 AM
  • User30537209 posted

    Oh my God,

    It is not the dbo.GetStudentCountWithoutNG_W that is causing the problem, but it is dbo.GetLetterGradeStatCount!

    I have used dbo.GetStudentCount inside dbo.GetLetterGradeStatCount and since it was renamed it was causing the error. The mssql wasn't telling me that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 6, 2012 5:19 AM