Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL71561 error - ambiguous reference

Error   431 SQL71561: 
Computed Column: [dbo].[ViewAlertFrequency].[BeginDate] contains an unresolved 
reference to an object. 
Either the object does not exist or the reference is ambiguous because it could 
refer to any of the following objects: 
[Lookup].[dbo].[AlertFrequency].[AlertFrequency]::[BeginDate] 
or [Lookup].[dbo].[AlertFrequency].[BeginDate]  

The current database is Lookup, so there shouldn't be any issues finding this object. This is imported from an existing view. It appears that the whole database is like this. I'm not sure what the :: syntax is.

Here is the view:

CREATE VIEW [dbo].[ViewAlertFrequency]

AS

--###
--ViewAlertFrequency
--###

--###
--used by: eobResolve
--###

SELECT DISTINCT TOP 100
    AlertFrequency.[ID]     AS [ID],
    AlertFrequency.Code     AS Code,
    AlertFrequency.[Name]       AS [Name],
    AlertFrequency.[Description]    AS [Description],
    AlertFrequency.[Rank]       AS [Rank],
    AlertFrequency.BeginDate    AS BeginDate,
    AlertFrequency.EndDate      AS EndDate

FROM         
    Lookup.dbo.AlertFrequency   AS AlertFrequency

ORDER BY
    AlertFrequency.[Rank]       ASC


GO
GRANT SELECT
    ON OBJECT::[dbo].[ViewAlertFrequency] TO [eobResolve]
    AS [dbo];
like image 824
Keith Walton Avatar asked Jun 29 '13 01:06

Keith Walton


1 Answers

You're using 3-part naming conventions in the "FROM" clause. Change "Lookup.dbo.AlertFrequency" to "dbo.AlertFrequency" and your problem should go away. I've had mixed results with this. Changing one of the DB options seemed to be enough to resolve those 3-part names, but I then ran into other issues with cross-database references (4-part names). I figured just changing the 3-part names to 2-part [schema].[object] naming would be the easier way to handle that.

The GRANT statement is just specifying that the permission is being granted to an object as opposed to a schema. I don't think that belongs in the object definition, but we handle our permissions in post-deploy scripts because they differ slightly from one environment to the next.

like image 114
Peter Schott Avatar answered Sep 26 '22 02:09

Peter Schott