JR
05/06/2024, 8:34 PMClay Roper
05/06/2024, 9:09 PMJR
05/06/2024, 9:48 PMClay Roper
05/06/2024, 9:56 PMJR
05/06/2024, 10:10 PMClay Roper
05/06/2024, 10:20 PMJR
05/07/2024, 8:50 PMClay Roper
05/07/2024, 8:56 PMJR
05/07/2024, 8:58 PMJR
05/07/2024, 8:58 PMWITH so_locations AS (
SELECT
transaction,
location
FROM transactionline
WHERE mainline = 'T'
/* GROUP BY location */
)
SELECT
so_locations.transaction,
line.mainline,
so_locations.location,
BUILTIN.DF(tran.ID) AS TranId,
tran.ID,
tran.type,
line.item,
line.itemType ,
BUILTIN.DF( line.Item ) AS ItemID,
line.foreignamount
FROM transactionline AS line
JOIN transaction AS tran
ON tran.id = line.transaction
JOIN so_locations
ON so_locations.transaction = line.transaction
WHERE
tran.type = 'SalesOrd'
AND line.mainline = 'F'
AND tran.TranDate >= '5/1/2024'
AND tran.TranDate < '6/1/2024'
AND line.itemType in ('InvtPart', 'Discount', 'Service')
AND tran.custbody2 NOT LIKE ('%x%')
ORDER BY
so_locations.location
/*
GROUP BY
tran.ID
*/
Clay Roper
05/07/2024, 8:59 PMJR
05/07/2024, 9:00 PMClay Roper
05/07/2024, 9:01 PMJR
05/07/2024, 9:01 PMJR
05/07/2024, 9:45 PMJR
05/07/2024, 9:45 PMWITH so_locations AS (
SELECT
transaction,
location
FROM transactionline
WHERE mainline = 'T'
)
SELECT
so_locations.location,
SUM(line.foreignamount) AS AMT
/* BUILTIN.DF(so_locations.location), */
FROM transactionline AS line
JOIN transaction AS tran
ON tran.id = line.transaction
JOIN so_locations
ON so_locations.transaction = line.transaction
WHERE
tran.type = 'SalesOrd'
AND line.mainline = 'F'
AND tran.TranDate >= '5/1/2024'
AND tran.TranDate < '6/1/2024'
AND line.itemType in ('InvtPart', 'Discount', 'Service')
AND tran.custbody2 NOT LIKE ('%x%')
GROUP BY
so_locations.location
ORDER BY
so_locations.location
/*
so_locations.transaction
line.mainline,
BUILTIN.DF(tran.ID) AS TranId,
tran.ID,
tran.type,
line.item,
line.itemType ,
BUILTIN.DF( line.Item ) AS ItemID,
AVG(line.foreignamount) AS AMT
ORDER BY
so_locations.transaction
GROUP BY
so_locations.location
HAVING
tran.ID > 0
Transaction.TranDate >= '4/1/2024'
AND Transaction.TranDate < '5/1/2024'
AND Transaction.Type = 'SalesOrd'
AND TransactionLine.Mainline = 'F'
AND TransactionLine.itemType in ('InvtPart', 'Discount', 'Service')
AND Transaction.custbody2 NOT LIKE ('%x%')
*/
JR
05/07/2024, 9:46 PMClay Roper
05/07/2024, 9:51 PMWITH so_locations AS (
SELECT
transaction,
location AS location_id,
BUILTIN.DF(location) AS location_name
FROM transactionline
WHERE mainline = 'T'
)
then you'd have location_id
for your joining and ordering, and location_name
for the resultsJR
05/07/2024, 9:56 PMClay Roper
05/09/2024, 2:06 PMJR
05/09/2024, 9:21 PMJR
05/09/2024, 9:21 PMWITH so_locations AS (
SELECT
transaction,
BUILTIN.DF(location) AS location_name
FROM transactionline
WHERE mainline = 'T'
)
SELECT
location_name,
MAX(line.item) AS mylineitem,
(SUM(line.foreignamount) * -1) AS 'Retail Sales',
CASE
WHEN location_name = 'Los Angeles' THEN '[ $667,000 ]'
WHEN location_name = 'New York' THEN '[ $667,000 ]'
WHEN location_name = 'San Francisco' THEN '[ $200,000 ]'
WHEN location_name = 'Seattle' THEN '[ $667,000 ]'
END AS target,
CASE
WHEN location_name = 'Los Angeles' THEN 667000 - SUM(line.foreignamount)
WHEN location_name = 'New York' THEN 667000 - SUM(line.foreignamount)
WHEN location_name = 'San Francisco' THEN 667000 - SUM(line.foreignamount)
WHEN location_name = 'Seattle' THEN 667000 - SUM(line.foreignamount)
END AS progress,
CASE
/* WHEN ((location_name = 'Los Angeles') AND (line.item LIKE '%assembly%')) THEN '-999' */
WHEN location_name = 'New York' THEN '[ $667,000 ]'
WHEN location_name = 'San Francisco' THEN '[ $200,000 ]'
WHEN location_name = 'Seattle' THEN '[ $667,000 ]'
END AS 'Move Sales',
CASE
/* WHEN ((location_name = 'Los Angeles') AND (tran.division = 'Contract')) THEN '-999' */
WHEN location_name = 'New York' THEN '[ $667,000 ]'
WHEN location_name = 'San Francisco' THEN '[ $200,000 ]'
WHEN location_name = 'Seattle' THEN '[ $667,000 ]'
END AS 'Contract Sales'
FROM transactionline AS line
JOIN transaction AS tran
ON tran.id = line.transaction
JOIN so_locations
ON so_locations.transaction = line.transaction
WHERE
tran.type = 'SalesOrd'
AND line.mainline = 'F'
AND tran.TranDate >= '4/1/2024'
AND tran.TranDate < '5/1/2024'
AND line.itemType in ('InvtPart', 'Discount', 'Service')
AND tran.custbody2 NOT LIKE ('%x%')
GROUP BY
so_locations.location_name
ORDER BY
so_locations.location_name
JR
05/09/2024, 9:21 PMClay Roper
05/09/2024, 9:34 PMline.item
will return the integer internal ID - if you want to compare the text of the item name, you should use BUILTIN.DF(line.item)
. If the text "Assembly" would be elsewhere, such as the item description, you'll need to join the item table in, or, if you trust that staff won't be editing the description, you could use line.memo
I suspect the same is true of division
, that it's a List/Record type field and returns the internal ID if you don't join or use BUILTIN.DF
JR
05/10/2024, 12:15 AMJR
05/10/2024, 12:15 AMWITH so_locations AS (
SELECT
transaction,
BUILTIN.DF(location) AS location_name
FROM transactionline
WHERE mainline = 'T'
)
SELECT
location_name,
CASE
WHEN ((location_name = 'Los Angeles') AND (BUILTIN.DF(line.item) LIKE '%assembly%')) THEN 'LA Move'
WHEN ((location_name = 'New York') AND (BUILTIN.DF(line.item) LIKE '%assembly%')) THEN 'NY Move'
WHEN ((location_name = 'San Francisco') AND (BUILTIN.DF(line.item) LIKE '%assembly%')) THEN 'SF Move'
WHEN ((location_name = 'Seattle') AND (BUILTIN.DF(line.item) LIKE '%assembly%')) THEN 'SEA Move'
END AS 'Move Sales'
FROM transactionline AS line
JOIN transaction AS tran
ON tran.id = line.transaction
JOIN so_locations
ON so_locations.transaction = line.transaction
WHERE
tran.type = 'SalesOrd'
AND line.mainline = 'F'
AND tran.TranDate >= '4/1/2024'
AND tran.TranDate < '5/1/2024'
AND line.itemType in ('InvtPart', 'Discount', 'Service')
AND tran.custbody2 NOT LIKE ('%x%')
GROUP BY
so_locations.location_name
ORDER BY
so_locations.location_name
Clay Roper
05/10/2024, 2:29 PM