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

  • Home
  • SEARCH
  • 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 8643715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:07:09+00:00 2026-06-12T12:07:09+00:00

I am trying to write a crystal report using a sql statement because it

  • 0

I am trying to write a crystal report using a sql statement because it runs much much faster. But I am having trouble with some of the linkings. I need to use the result of a link for criteria in subsequent links.

Ok, here is a sample of what my statement looks like:

(The lines marked with ** are the lines in question)

SELECT
    Part.PartNum,
    Cust.CustNum,
    Cust.CustID,
    YTD.Qty
FROM
    (
    SELECT
        Pub.Part.PartNum,
        Pub.Part.UserChar1 AS CustID
    FROM
        Pub.Part
    ) AS Part
        LEFT OUTER JOIN (
            SELECT
                Pub.Customer.CustID,
                Pub.Customer.CustNum,
                Pub.Customer.Name
            FROM
                Pub.Customer
            WHERE
                Pub.Customer.CustID = '1038'
        ) AS Cust 
            ON Part.CustID = Cust.CustID
        LEFT OUTER JOIN (
            SELECT
                Pub.OrderDtl.PartNum,
                Sum(Pub.OrderDtl.OrderQty) AS Qty
            FROM
                Pub.OrderHed JOIN Pub.OrderDtl ON
                    Pub.OrderHed.OrderNum = Pub.OrderDtl.OrderNum
            WHERE
                **Pub.OrderHed.CustNum = Cust.CustNum AND**
                **Pub.OrderDtl.PartNum = Part.PartNum AND**
                YEAR(Pub.OrderHed.OrderDate)=YEAR(CURDATE())
            GROUP BY 
                Pub.OrderDtl.PartNum
        ) AS YTD ON Part.PartNum = YTD.PartNum

Now, I get an error that says:

Part.PartNum cannot be found or is not specified for the query.

I get the same error for Cust.CustNum. Will you help me figure out what I am doing wrong? Thanks!

  • 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-12T12:07:10+00:00Added an answer on June 12, 2026 at 12:07 pm

    The problem is that you are using one of the aliases, inside of a sub-query which you cannot do. You will have to do something similar to this:

    SELECT Part.PartNum,
      Cust.CustNum,
      Cust.CustID,
      YTD.Qty
    FROM
    (
      SELECT Pub.Part.PartNum,
        Pub.Part.UserChar1 AS CustID
      FROM Pub.Part
    ) AS Part
    LEFT OUTER JOIN
    (
      SELECT Pub.Customer.CustID,
        Pub.Customer.CustNum,
        Pub.Customer.Name
      FROM Pub.Customer
      WHERE Pub.Customer.CustID = '1038'
    ) AS Cust
      ON Part.CustID = Cust.CustID
    LEFT OUTER JOIN
    (
      SELECT Pub.OrderDtl.PartNum,
        Sum(Pub.OrderDtl.OrderQty) AS Qty,
        Pub.OrderHed.CustNum
      FROM Pub.OrderHed 
      JOIN Pub.OrderDtl 
        ON Pub.OrderHed.OrderNum = Pub.OrderDtl.OrderNum
      WHERE YEAR(Pub.OrderHed.OrderDate)=YEAR(CURDATE())
      GROUP BY Pub.OrderDtl.PartNum, Pub.OrderHed.CustNum
    ) AS YTD
      ON Part.PartNum = YTD.PartNum
      AND Cust.CustNum = YTD.CustNum
    

    Looking at your query more, you can actually get rid of two of the subqueries:

    SELECT Part.PartNum,
      Cust.CustNum,
      Cust.CustID,
      YTD.Qty
    FROM Pub.Part Part
    LEFT OUTER JOIN Pub.Customer Cust
      ON Part.CustID = Cust.CustID
      AND Cust.CustID = '1038'
    LEFT OUTER JOIN
    (
      SELECT d.PartNum,
        Sum(d.OrderQty) AS Qty,
        h.CustNum
      FROM Pub.OrderHed h
      JOIN Pub.OrderDtl d
        ON h.OrderNum = d.OrderNum
      WHERE YEAR(h.OrderDate)=YEAR(CURDATE())
      GROUP BY d.PartNum
    ) AS YTD
      ON Part.PartNum = YTD.PartNum
      AND Cust.CustNum = YTD.CustNum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to export a report but everytime it runs the code to
Trying to write dynamic queries using the LINQ provider for NHibernate, but I am
I am trying write a function that generates simulated data but if the simulated
Trying to write out syslog entries containing strings but they don't register. // person.name
I'm trying to write a report to hit a very large database, which makes
Trying to write a windows speech recognition macro. Written using XML and scripting language
Trying to write Unit test for Silverlight 4.0 using Moq 4.0.10531.7 public delegate void
I'm trying write a simple perl script that reads some fields from a password
Trying to write a handler for a packet sniffer. I'm having issues with casting
So, I'm having a little trouble trying to make a card reader work properly

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.