2014-12-24 50 views
0
ALTER PROCEDURE [dbo].[SP_GET_DDLPage] 
AS 
BEGIN 
    SELECT NULL AS 'ID', '--None--' AS 'DSC' 
    UNION 
    SELECT MSP_NM AS 'ID', MSP_TITLE AS 'DSC' 
    FROM MST_PAGE 
    WHERE MSP_STS = ACTIVE ORDER BY MSP_NM 
END 

我得到一個錯誤說:的MySQL應用的 「ORDER BY」 子句UNION查詢

MSP_NM是無效的列

我該如何解決這個問題的查詢,也爲了通過MSP_NM

+0

這看起來更像是SQL Server的語法,而不是MySQL,標識符周圍的方括號以及對「dbo」,「ALTER PROCEDURE」語句的引用... – spencer7593

回答

0

我認爲這是最好使用子查詢爲此:

SELECT * 
FROM (SELECT NULL AS ID, '--None--' AS DSC 
     UNION ALL 
     SELECT MSP_NM AS ID, MSP_TITLE AS DSC 
     FROM MST_PAGE 
     WHERE MSP_STS = 'ACTIVE' 
    ) t 
ORDER BY ID; 

您需要大約'ACTIVE'報價,你可能不運行子查詢的查詢 - 我只是覺得子查詢闡明意圖。

+0

yesyes我最近將其更改爲number to varchar hopin ppl瞭解,謝謝你先生,問題解決... – user3921882