如何使用(AS)TOTALNAME在哪里
SELECT
*, CITY + ' / ' + NAME AS TOTALNAME
FROM
FARKETMEZ
WHERE
TOTALNAME like '%TURKEY%'
答案 0 :(得分:2)
您不能使用与ALIAS
子句在同一级别上提供的WHERE
。
您有两种选择:
查询:
SELECT *, CITY + ' / ' + NAME AS TOTALNAME
FROM FARKETMEZ
WHERE TOTALNAME like '%TURKEY%'
查询:
SELECT *
FROM
( SELECT *, CITY + ' / ' + NAME AS TOTALNAME
FROM FARKETMEZ
) a
WHERE TOTALNAME like '%TURKEY%'
SQL操作顺序如下:
无法直接使用它的原因是因为WHERE
子句首先在创建SELECT
的{{1}}语句之前执行。
答案 1 :(得分:2)
您不能直接使用派生表,也不能使用CTE(SQL Server 2005 +):
派生表:
SELECT *
FROM ( SELECT
*, CITY + ' / ' + NAME AS TOTALNAME
FROM
FARKETMEZ
) AS T
WHERE TOTALNAME like '%TURKEY%'
CTE:
;WITH CTE AS
(
SELECT
*, CITY + ' / ' + NAME AS TOTALNAME
FROM
FARKETMEZ
)
SELECT *
FROM CTE
WHERE TOTALNAME like '%TURKEY%'