Can you tell me what this code is doing? No opening parenthesis

Below is the end of a script. There are a series of does not equal filters followed by a closing parenthesis. There is no opening parenthesis, what is the closing parenthesis accomplishing? Following the closing parenthesis is "AS SQ", what is this applying the 'SQ' alias to?

F4211.SDUORG/100000 AS 'Qty Ordered',
F4211.SDSOBK/100000 AS 'Qty Backordered',
Case When SDNXTR > '570' Then F4211.SDSOQS/100000 Else 0 End as 'Qty Shipped',
(F4211.SDUORG/100000 * F4211.SDUPRC/100000) as 'Total Price',
F4211.SDUORG/100000 * (Select TOP(1) COUNCS/10000 From JDE_PDQUERY.PRODDTA.F4105 Where COMCU=F4211.SDMCU and COITM=F4211.SDITM and COCSIN='I') as 'Total Cost',
Replace((select abalky from JDE_PDQUERY.PRODDTA.f0101 where aban8=(SELECT TOP (1) CMSLSM FROM JDE_PDQUERY.PRODDTA.F42140 AS F42140 WHERE (CMAN8 = SDAN8))),' ','') as 'Salesperson',
SDTORG as 'Originator'
WHERE F4211.SDLTTR<>'980' and Substring(F4211.SDGLC,1,2) <> 'FT' and F4211.SDDCTO <> 'SQ' and F4211.SDDCTO <> 'ST' AND SDNXTR>'565') AS SQ Where [Date Shipped] IS NOT NULL AND [Date Shipped]>=GETDATE()-1096

It is a table alias for the above query

By the way this is a very oogly query

There is an opening paren:

F4211.SDUORG/100000 * ( Select TOP(1) COUNCS/10000 From JDE_PDQUERY.PRODDTA.F4105

1 Like

Your Code = Formatted

F4211.sduorg/100000 AS 'Qty Ordered', f4211.sdsobk/100000 AS 'Qty Backordered',
WHEN sdnxtr > '570' THEN
  ELSE 0
AS 'Qty Shipped', (f4211.sduorg/100000 * f4211.sduprc/100000) AS 'Total Price', f4211.sduorg/100000 *
       SELECT TOP(1)
       FROM   jde_pdquery.proddta.f4105
       WHERE  comcu=f4211.sdmcu
       AND    coitm=f4211.sditm
       AND    cocsin='I') AS 'Total Cost', replace(
       SELECT abalky
       FROM   jde_pdquery.proddta.f0101
       WHERE  aban8=
                     SELECT TOP (1)
                     FROM   jde_pdquery.proddta.f42140 AS f42140
                     WHERE  (
                                   cman8 = sdan8))),' ','') AS 'Salesperson', sdtorg AS 'Originator' FROM jde_pdquery.proddta.f4211 f4211 (nolock) WHERE f4211.sdlttr<>'980'
substring(f4211.sdglc,1,2) <> 'FT'
f4211.sddcto <> 'SQ'
f4211.sddcto <> 'ST'
sdnxtr>'565') AS sq WHERE [Date Shipped] IS NOT NULL
[Date Shipped]>=getdate()-1096
1 Like

your code what you put
Parenthesis Diagram

this is a very very common issue .. how do you figure out ? methods ?

1 Like

much better to do it

in small pieces

temp tables

Thank you to those that replied. Very helpful. I don't write SQL and am working on modifying this to my purposes.

Often not. I doubt it for the query above.

But you do need to change this WHERE condition:
substring(f4211.sdglc,1,2) <> 'FT'
f4211.sdglc NOT LIKE 'FT%'

Because that can make better use of potential indexes.