我正在尝试选择多个列值并将它们连接到一列中。然后,我想在选择值的列上运行一个LIKE。然而,它似乎不起作用。
下面是我的SQL查询。
SELECT col1 + ' ' + col2 + ' ' + col3 AS colname
FROM tblname
WHERE 'colname' LIKE 'test%'这个查询有什么问题?有没有更好的方法来做这件事?
发布于 2012-01-02 09:31:39
SELECT
col1 + ' ' + col2 + ' ' + col3 AS colname
FROM tblname
WHERE (col1 + ' ' + col2 + ' ' + col3) LIKE 'test%'或
select *
from
(
SELECT
col1 + ' ' + col2 + ' ' + col3 AS colname
FROM tblname
)a
WHERE colname LIKE 'test%'这是因为不能在WHERE子句中使用列别名。您需要显式地确定别名定义的内容,或者使用子查询来抽象别名。
https://stackoverflow.com/questions/8696762
复制相似问题