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 8224529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:06:06+00:00 2026-06-07T15:06:06+00:00

Hi I am doing a subquery to get value of cTL column But i

  • 0

Hi I am doing a subquery to get value of cTL column But i need value of outer column in the subquery for right response
but i get error that it doesn’t recognize the SC and RC varaibles. ANy way out?

SELECT DISTINCT(cStoreCode) as SC
    ,cRetailerCode as RC
    , cStoreCode + ' - ' + cStoreName AS Store,
    x.TeamLead 
FROM
(
    SELECT cTL as TeamLead 
    FROM tblEmpSchedule 
    WHERE   cRepCode LIKE @repCode AND
        cClientCode LIKE @gCode AND
        cProjectCode LIKE @pCode AND
        cYear LIKE @year AND
        cCycleNo LIKE @cycleNo AND
        cRetailerCode LIKE @retailerCode AND
        cStoreCode = SC AND
        cRetailerCode = RC
 )x
,tblEmpSchedule 
WHERE cRepCode LIKE @repCode AND
    cClientCode LIKE @gCode AND
    cProjectCode LIKE @pCode AND
    cYear LIKE @year AND
    cCycleNo LIKE @cycleNo AND
    cRetailerCode LIKE @retailerCode AND
    cStoreCode <> '' AND cStoreCode is Not Null
ORDER BY cStoreCode
  • 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-07T15:06:09+00:00Added an answer on June 7, 2026 at 3:06 pm

    No, you can’t reference an alias for an expression like that, in a WHERE clause. An alias for an expression can be referenced in a WHERE clause ONLY if it’s from an inline view or CTE (referenced in the FROM clause.)

    The use of the DISTINCT keyword looks peculiar. There’s no need to wrap the first expression in the SELECT list in parenthesis. Your construct makes it almost look like it were a function call. (It isn’t, that DISTINCT keyword applies to ALL of the expressions in your SELECT list).

    It’s not at all clear why you need a JOIN operation here.

    I hate to answer a question with a question, but… What are you trying to gain by using an inline view to get a value from the cTL column aliased as TeamLead? What problem is that supposed to be solving? Why does the table need to be referenced twice?

    To ask the same question another way…

    What’s “wrong” with the result set returned by a query on the tblEmpSchedule table, like this one?

    SELECT DISTINCT s.cStoreCode             AS sc
         , s.cRetailerCode                   AS rc
         , s.cStoreCode + ' - ' + cStoreName AS Store
         , s.cTL                             AS TeamLead
      FROM tblEmpSchedule s
     WHERE s.cRepCode LIKE @repCode AND
           s.cClientCode LIKE @gCode AND
           s.cProjectCode LIKE @pCode AND
           s.cYear LIKE @year AND
           s.cCycleNo LIKE @cycleNo AND
           s.cRetailerCode LIKE @retailerCode AND
           s.cStoreCode <> ''
     ORDER BY s.cStoreCode
    

    If you can explain why the result set returned by this query differs from what you need, then I (or someone else) may be able to help. As your question stands, it’s not clear what you are trying to achieve.

    NOTE: the “cStoreCode IS NOT NULL” predicate in your query is redundant. We already know it can’t be NULL if the “cStoreCode <> ''” predicate returns TRUE.

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

Sidebar

Related Questions

Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'
Doing a simple Squeryl database lookup, but trying to exclude a value. I've tried:
I am doing easy web based chat so I need to get (for example)
So this is what i thought of doing but now the error i am
I'm trying to accomplish a query that requires a calculated column using a subquery
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing code analysis of the project and get the message Reference-counted object is used
I need to know if there is a possible way doing this with out
I don't even know if I am doing this query the right way. There
I'm doing an update to a temp table in Oracle. My thinking was that

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.