on 2024 Jul 05 12:47 PM
Hello,
I created the query below. This works properly.
But I actually want the query to return only the lines that have the value WAAR.
What's the best way to do that? I don't think I can put the name of the column header in the WHERE section.
SELECT
T0.[ItemCode],
T0.[ItemName],
T1.[Price] as 'Inkoopprijs',
T0.[AvgPrice],
CASE WHEN T1.[Price] = T0.[AvgPrice] THEN 'WAAR' ELSE 'ONWAAR' END AS 'Gelijk?'
FROM
OITM T0 INNER JOIN ITM1 T1 ON T0.[ItemCode] = T1.[ItemCode]
WHERE
T1.[PriceList] = [%0] AND
T0.[InvntItem] = 'Y' AND
T0.[frozenFor] = 'N'
Request clarification before answering.
SELECT
T0.[ItemCode],
T0.[ItemName],
T1.[Price] as 'Inkoopprijs',
T0.[AvgPrice],
CASE WHEN T1.[Price] = T0.[AvgPrice] THEN 'WAAR' ELSE 'ONWAAR' END AS 'Gelijk?'
FROM
OITM T0 INNER JOIN ITM1 T1 ON T0.[ItemCode] = T1.[ItemCode]
WHERE
T1.[PriceList] = [%0] AND
T0.[InvntItem] = 'Y' AND
T0.[frozenFor] = 'N'
AND T1.[Price] = T0.[AvgPrice]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please check this example
SELECT
ItemCode,
ItemName,
Inkoopprijs,
AvgPrice,
Gelijk
FROM (
SELECT
T0.ItemCode,
T0.ItemName,
T1.Price AS Inkoopprijs,
T0.AvgPrice,
CASE WHEN T1.Price = T0.AvgPrice THEN 'WAAR' ELSE 'ONWAAR' END AS Gelijk
FROM OITM T0
INNER JOIN ITM1 T1 ON T0.ItemCode = T1.ItemCode
WHERE
T1.PriceList = [%0] AND
T0.InvntItem = 'Y' AND
T0.frozenFor = 'N'
) WHERE Gelijk = 'WAAR';
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jeroenw ,
You could just include an additional condition to your WHERE clause:
SELECT
T0.[ItemCode],
T0.[ItemName],
T1.[Price] as 'Inkoopprijs',
T0.[AvgPrice],
CASE WHEN T1.[Price] = T0.[AvgPrice] THEN 'WAAR' ELSE 'ONWAAR' END AS 'Gelijk?'
FROM
OITM T0 INNER JOIN ITM1 T1 ON T0.[ItemCode] = T1.[ItemCode]
WHERE
T1.[PriceList] = [%0] AND
T0.[InvntItem] = 'Y' AND
T0.[frozenFor] = 'N' AND
(SELECT CASE WHEN T1.[Price] = T0.[AvgPrice] THEN 'WAAR' ELSE 'ONWAAR' END AS 'Gelijk?') = 'WAAR'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.