troubleshooting Question

SQL - Syntax Queries

Avatar of Zack
ZackFlag for Australia asked on
SQLMicrosoft SQL Server
2 Comments1 Solution13 ViewsLast Modified:
Hi EE,

I have the following query:

SELECT
    A.[VENDOR NAME] AS 'VENDOR NAME',
    A.[VENDOR NUMBER] AS 'VENDOR NUMBER'
FROM
    (SELECT
        PURCHTABLE.PURCHNAME AS 'VENDOR NAME',
        PURCHTABLE.ORDERACCOUNT AS 'VENDOR NUMBER',
        COUNT(DISTINCT PURCHTABLE.PURCHID) AS 'PURCHASE ORDER',
        COUNT(PURCHLINE.LINENUMBER) AS 'NUMBER OF LINES',
        SUM(PURCHLINE.LINEAMOUNT) AS 'PO PRICE TOTAL',
        DATEDIFF(dd, PURCHTABLE.CONFIRMEDDLV, MAX(VENDPACKINGSLIPJOUR.DELIVERYDATE))-(DATEDIFF(wk, PURCHTABLE.CONFIRMEDDLV, MAX(VENDPACKINGSLIPJOUR.DELIVERYDATE)) * 2)-(CASE WHEN DATENAME(dw, PURCHTABLE.CONFIRMEDDLV) = 'Sunday' THEN 1 ELSE 0 END)-(CASE WHEN DATENAME(dw, MAX(VENDPACKINGSLIPJOUR.DELIVERYDATE)) = 'Saturday' THEN 1 ELSE 0 END) AS 'DAYS LATE'
    FROM
    PURCHTABLE
    JOIN
    PURCHLINE ON PURCHLINE.PURCHID = PURCHTABLE.PURCHID
    JOIN
    VENDPACKINGSLIPJOUR ON VENDPACKINGSLIPJOUR.PURCHID = PURCHTABLE.PURCHID
    WHERE
    PURCHTABLE.DELIVERYDATE >= '2019-01-01'
    AND
    PURCHTABLE.DELIVERYDATE <= '2019-01-20'
    AND
    PURCHTABLE.ORDERACCOUNT = 'FDS5834') as A
   
GROUP BY  
A.[VENDOR NAME],
A.[VENDOR NUMBER],
A.[PURCHASE ORDER],
PURCHTABLE.CONFIRMEDDLV

Getting the following errors

Msg 8120, Level 16, State 1, Line 6
Column 'PURCHTABLE.PURCHNAME' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 4104, Level 16, State 1, Line 29
The multi-part identifier "PURCHTABLE.CONFIRMEDDLV" could not be bound.

Both these tables/columns exist and the PURCHTABLE.PURCHNAME' have appropriate aliases.

Any assistance is welcome.

Thank you. 


ASKER CERTIFIED SOLUTION
Peter Chan
IT Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros