Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7892383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:51:22+00:00 2026-06-03T06:51:22+00:00

I have not been able to figure out scope of reference when there are

  • 0

I have not been able to figure out scope of reference when there are nested queries. For example I can’t seem to reference NoCarsFound.CU in my inner join. I don’t understand why in my join I can’t reference previous result sets…I think I just don’t undrestand the scope of referencing previous select results or referencing aliases in my inner join’s ON comparisons.

I also get Ambiguous column name ‘CU’

So I keep getting errors saying it doesn’t know NoCarsFound.CU. I even tried to reference a straight view such as vwInvalidCars.CU, and it doesn’t understand vwInvalidCars either.

create procedure [Rac].[GetCarStatDetails_sp]
    @Year int,
    @CarTitle varchar(30),
    @Company varchar(31),
    @CU varchar(12),
    @UserName varchar(50)
as
BEGIN

DECLARE @CarMatch table
(
    FaceValueTol varchar(100),
    FaceValueDesc varchar(100),
    Year int,
    CU varchar(16),
    PaintTypeDesc varchar(50)

)

insert into @CarMatch
    Select  temp1.FaceValueTol,
            temp1.FaceValueDesc,      
            temp1.Year,
            temp1.CU,
            temp1.PaintTypeDesc
    from    Rac.viewCarBase as temp1  
    join (select Username, userCars.CU from Nep.viewUserCars userCars where UserName = @UserName) as userCars on userCars.CU = temp1.CU
    INNER JOIN
    (
        Select  CU,
                from Rac.vwCarFactor carfactors
        where RiskFactorTypeID not in (334,553,34334,534,7756)
        Group by    CU
    ) as temp
    on 
        and temp1.CU = temp.CU 
        and temp1.PaintTypeDesc  = temp.CalcPaintTypeDesc 
    Where
        temp1.RiskFactorTypeID=4
        and temp1.[Year]=@Year
        and (temp1.CarTitle=@CarTitle or @CarTitle='<All>')
        and (temp1.CU=@CU or @CU='<All>')

SELECT  ProductID_bo,
        Coalesce(CarTitle_bo,LTRIM(RTRIM(CarTitle))) as CarTitle, 
        Coalesce(Company_bo,LTRIM(RTRIM(Company))) as Company, 
        Coalesce(CU_bo,LTRIM(RTRIM(CU))) as CU
    FROM
        Rac.viewCarBase as NoCarsFound
        join (select Username, userCars.CU from Nep.viewUserCars userCars where UserName = @UserName) as userCars on userCars.CU = NoCarsFound.CU
    LEFT OUTER JOIN
    (
        Select  ProductID_bo,
                CarTitle_bo, 
                Company_bo,
                CU_bo,
        from (
                SELECT  ProductID as ProductID_bo,
                        LTRIM(RTRIM(CarTitle)) as CarTitle_bo, 
                        LTRIM(RTRIM(Company)) as Company_bo, 
                FROM    Rac.viewCarBase
                join (select Username, userCars.CU from Nep.viewUserCars userCars where UserName = @UserName) as userCars on userCars.CU = Rac.viewCarBase.CU
                where   ProductID in (Select ProductID from @CarMatch) and
                        and (CarTitle=@CarTitle or @CarTitle='<All>')
                        and (Company=@Company or @Company='<All>')
                        and (CU=@CU or @CU='<All>')

            ) AS SUB1

        Group By    
                    CarTitle_bo, 
                    Company_bo,
                    CU_bo,
        ON
                NoCarsFound.CU = CarsFoundDeals.CU_bo
    where 
        and (CarTitle=@CarTitle or @CarTitle='<All>')
        and (Company=@Company or @Company='<All>')
        and (CU=@CU or @CU='<All>')

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:51:23+00:00Added an answer on June 3, 2026 at 6:51 am

    I would look at the two following pieces of SQL from what you have above:

    LEFT OUTER JOIN
    (
        Select  ProductID_bo,
                CarTitle_bo, 
                Company_bo,
                CU_bo,
        from (
                SELECT  ProductID as ProductID_bo,
                        LTRIM(RTRIM(CarTitle)) as CarTitle_bo, 
                        LTRIM(RTRIM(Company)) as Company_bo, 
                FROM    Rac.viewCarBase
                join (select Username, userCars.CU from Nep.viewUserCars userCars where UserName = @UserName) as userCars on userCars.CU = Rac.viewCarBase.CU
                where   ProductID in (Select ProductID from @CarMatch) and
                        and (CarTitle=@CarTitle or @CarTitle='<All>')
                        and (Company=@Company or @Company='<All>')
                        and (CU=@CU or @CU='<All>') --<--HERE!!!!!!!!!!!!!!!!!!!!!!!!
    
            ) AS SUB1
    

    and

    where 
        and (CarTitle=@CarTitle or @CarTitle='<All>')
        and (Company=@Company or @Company='<All>')
        and (CU=@CU or @CU='<All>') -- <--HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    

    Both of these appear to be referencing CU in a way that could potentially cause the error you are reporting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done some searching around but have not been able to figure out
One question whose answer I have not been able to figure out in whole
This error is a nightmare, I have not been able to figure out why
I'm new to GAE, and have not been able to figure out how to
I am having two issues that I have not been able to figure out.
I have not been able to find any definitive answers to this question: Can
I have been using this as a reference, but not able to accomplish exactly
From all the various examples of Ember.js, I have not been able to figure
This is something that I cannot believe I have not been able to figure
I have seen the abbreviation WS-*, but I have not been able to figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.