where condition in sql with newly created field

旧街凉风 提交于 2019-12-24 08:57:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!