Forum Discussion
HelenH2300
Oct 24, 2024Copper Contributor
SQL WHERE Statement
I am trying to write a query where the date used could be one of 3 depending on if the dates are valid or not. In the screenshot below I have managed to create a field PODate to contain the corre...
LainRobertson
Oct 24, 2024Silver Contributor
You can't use the [PODate] label in the WHERE clause. You have to copy-and-paste (as they need to remain identical in both locations) the CASE...END statement from the SELECT block to the WHERE block - being sure to leave off the trailing "AS PODate".
So, your WHERE panel would change:
AND (PODate <= GETDATE())
To:
AND (
CASE
WHEN ... THEN ...
WHEN ... THEN ...
ELSE ...
END <= GETDATE()
)
The only place you can reference the [PODate] (based on your screenshot) is in the ORDER BY panel.
Cheers,
Lain
- HelenH2300Oct 24, 2024Copper ContributorThanks, that gives me just what I wanted
Helen- olafhelperOct 25, 2024Bronze ContributorWHERE is a pre-processor command, while SELECT and ORDER by are post-processor commands.
You can not use alias defined in post in a pre command.