-3
SELECT
*, CITY + '/' + NAME AS TOTALNAME
FROM
FARKETMEZ
WHERE
TOTALNAME like '%TURKEY%'
SELECT
*, CITY + '/' + NAME AS TOTALNAME
FROM
FARKETMEZ
WHERE
TOTALNAME like '%TURKEY%'
不能使用這是在同一水平WHERE
條款給出的ALIAS
(AS)TOTALNAME。
你有兩個選擇:
查詢:
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
子句中正在創建ALIAS
的SELECT
語句之前先執行。
不能直接,要麼使用派生表,或者您可以使用一個CTE(SQL服務器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%'
您不能在同一級別的where子句中使用列別名 – 2013-04-30 15:35:50