|
Posted by Steve on 11/29/05 00:58
> This query works fine as is, but I can't seem to use the generated
> field in a WHERE clause at the end. Say you have a much larger table
> like the one mentioned above, and you want to add a "WHERE username =
> '(user no longer exists)' OR username = 'myusername'" to the end.
Refer to the original column name, not the aliased name. If it helps,
make the aliased name obviously different from the original...
SELECT
CASE ISNULL(username)
WHEN 1 THEN "(user no longer exists)"
ELSE username
END AS "username_x",
total_sales
FROM sales
LEFT OUTER JOIN users ON sales.userid = users.userid
WHERE ISNULL(username) OR username = "myusername"
---
Steve
Navigation:
[Reply to this message]
|