Jeg tror, du prøver at få adgang til validFrom
og validTo
fra sagsforespørgslen i where-tilstand. Hvis det er tilfældet, skal du omformatere din forespørgsel.
SELECT t1.* FROM ( SELECT mPrice, aPrice,
CASE
WHEN validFrom < '2013-11-01'
THEN '2013-11-01'
ELSE validFrom END AS validFrom,
CASE
WHEN validTo > '2013-11-30'
THEN '2013-11-30'
ELSE validTo END AS validTo
FROM commission) t1
WHERE ((t1.validfrom BETWEEN '2013-11-01' AND '2013-11-30') OR (t1.validto BETWEEN '2013-11-01' AND '2013-11-30')) ORDER BY t1.validFrom
Men dette vil give 3 resultater. Hvis du har brug for at få det forventede resultat, så skal du bruge en AND
betingelse i stedet for OR
.
Så bliver din forespørgsel
SELECT t1.* FROM ( SELECT mPrice, aPrice,
CASE
WHEN validFrom < '2013-11-01'
THEN '2013-11-01'
ELSE validFrom END AS validFrom,
CASE
WHEN validTo > '2013-11-30'
THEN '2013-11-30'
ELSE validTo END AS validTo
FROM commission) t1
WHERE ((t1.validfrom BETWEEN '2013-11-01' AND '2013-11-30') AND (t1.validto BETWEEN '2013-11-01' AND '2013-11-30')) ORDER BY t1.validFrom