Error using a derived table
From: James Rowland-Jones (anonymous_at_discussions.microsoft.com)
Date: 03/29/04
- Next message: David Browne: "Re: .NET dataset request from a complex SP <returns many tables>"
- Previous message: Konstantinos: "Re: Does sp_MSdependencies Backups Tran Log???"
- Next in thread: Anith Sen: "Re: Error using a derived table"
- Reply: Anith Sen: "Re: Error using a derived table"
- Reply: Adam Machanic: "Re: Error using a derived table"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 29 Mar 2004 07:21:14 -0800
SQL Server is returning the following error :
Server: Msg 107, Level 16, State 2, Line 4
The column prefix 'u' does not match with a table name or alias name used in the query.
With this SQL Statement :
declare @datasetuploadid int
set @datasetuploadid = 1
select
( case when u.otherregion is not null
and u.resort is not null
Then ( select d.regionid
from ( select top 1 resort.name,max(resort.regionid)as 'regionid',count(*) as 'counter'
from ( select r.name as 'Resortname'
,r.regionid as 'RegionID'
,r.regiontypeid as 'RegionTypeID'
from dbo.region r
where name = u.resort
and r.active = 1
and r.isresort = 1
union all
select s.misspelledname as 'Resortname'
,s.regionid as 'RegionID'
,r1.regiontypeid as 'RegionTypeID'
from dbo.similarname s
join dbo.region r1
on s.regionid = r1.regionid
where misspelledname = u.Resort
and r1.active = 1
and r1.isresort = 1
union all
select a.aliasname as 'Resortname'
,a.regionid as 'RegionID'
,r2.regiontypeid as 'RegionTypeID'
from dbo.alias a
join dbo.region r2
on a.regionid = r2.regionid
where aliasname = u.Resort
and r2.active = 1
and r2.isresort = 1
) resort
join dbo.childregion cr1
on resort.regionid = cr1.childid
where cr1.parentid IN ( select r.regionid as 'RegionID'
from dbo.region r
where name = u.OtherRegion
and r.active = 1
union all
select s.regionid as 'RegionID'
from dbo.similarname s
join dbo.region r1
on s.regionid = r1.regionid
where misspelledname = u.OtherRegion
and r1.active = 1
union all
select a.regionid as 'RegionID'
from dbo.alias a
join dbo.region r2
on a.regionid = r2.regionid
where aliasname = u.OtherRegion
and r2.active = 1
)
and resort.active = 1
and resort.isresort = 1
and resort.name = u.resort
group by resort.name,resort.regiontypeid
order by resort.regiontypeid desc
) d
where d.counter = 1
)
End
)
from dbo.uploadeditem u
where u.datasetuploadid = @datasetuploadid
and u.Resort_RegionID is null
and u.statuscodeid is null
I believe the error is due to the resort derived table not being able to resolve the 'u' table alias. I have found a Q article on this subject 225492 but it was only for SQL 7. I am using SQL Server 2000 EE.
So the question is am I doing something wrong or is this a bug?
Any help would be greatly appreciated.
James
- Next message: David Browne: "Re: .NET dataset request from a complex SP <returns many tables>"
- Previous message: Konstantinos: "Re: Does sp_MSdependencies Backups Tran Log???"
- Next in thread: Anith Sen: "Re: Error using a derived table"
- Reply: Anith Sen: "Re: Error using a derived table"
- Reply: Adam Machanic: "Re: Error using a derived table"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|