问题
I have the following query, why cant I get my where clause to work? The value does exist in the table.
Select B.*, B.[RF attribute1] & "|" & B.[RF attribute2] & "|" & B.[RF attribute3] & "|" & B.[RF attribute4] as new_field
FROM [Black$] as B
where new_field = "Stack|over||flow"
error message is No value given for one or more required paramters
Edit, Actual data:
+---------------+---------------+---------------+---------------+
| RF attribute1 | RF attribute2 | RF attribute3 | RF attribute4 |
+---------------+---------------+---------------+---------------+
| BONDZERO | AUD | | MID |
| BONDZERO | AUD | | MID |
| SWAPZERO | AUD | | MID |
| SWAPZERO | AUD | | MID |
which will create a new field like so:
+-------------------+
| new_field |
+-------------------+
| BONDZERO|AUD||MID |
| BONDZERO|AUD||MID |
| SWAPZERO|AUD||MID |
| SWAPZERO|AUD||MID |
+-------------------+
Now i am trying to use the where clause BONDZERO|AUD||MID
so it only returns the first 2 rows.
回答1:
Access thinks you are trying to pass new_field
as a parameter.
You need to rephrase your WHERE
clause verbosely:
Select B.*, B.[RF attribute1] & "|"
& B.[RF attribute2] & "|"
& B.[RF attribute3] & "|"
& B.[RF attribute4] as new_field
FROM [Black$] as B
where B.[RF attribute1] & "|"
& B.[RF attribute2] & "|"
& B.[RF attribute3] & "|"
& B.[RF attribute4] = "Stack|over||flow"
回答2:
Use a subquery:
select b.*
from (Select B.*, B.[RF attribute1] & "|" & B.[RF attribute2] & "|" & B.[RF attribute3] & "|" & B.[RF attribute4] as new_field
from [Black$] as B
) as b
where new_field = "Stack|over||flow";
来源:https://stackoverflow.com/questions/50683970/where-condition-in-sql-with-newly-created-field