2011-12-14 81 views
0

MySQL的大師,MySQL的DECLARE語法(從MSSQL轉換)

我把一些報告,從MSSQL數據庫的使用在一個MySQL數據庫,似乎不懂得如何在MySQL中DECLARE作品。以下是報告的SQL代碼,與MSSQL中的一樣。我讀DECLARE只能用於嵌套函數,我相信,但這聽起來不正確。

當前報表SQL:(我解析&從我的應用程序代碼替換當前&待定的值)

DECLARE @Current int; 
DECLARE @Pending int; 

SET @Current = [1]; 
SET @Pending = [3]; 

Select Ticket.TIcketID, 
ISNULL((Select LocationName from Location where LocationID = Ticket.SiteCurrentLocation), 'Invalid Location') as [Current Location], 
ISNULL((Select LocationName from Location where LocationID = Ticket.SitePendingLocation), 'Invalid Location') as [Pending Location] 
from Ticket 

where 
(SitePendingLocation > 0 AND SitePendingLocation <> SiteCurrentLocation) AND 
(SiteCurrentLocation = @Current OR @Current = 0) AND 
(SitePendingLocation = @Pending OR @Current = 0) 

任何見解?

謝謝 - 安德魯

編輯

工作,轉換腳本 - 它可以幫助別人:

SET @Current = '1'; 
SET @Pending = '1'; 

Select Ticket.TIcketID, 
IFNULL((Select LocationName from Location where LocationID = Ticket.SiteCurrentLocation), 'Invalid Location') as `Current Location`, 
IFNULL((Select LocationName from Location where LocationID = Ticket.SitePendingLocation), 'Invalid Location') as `Pending Location` 
from Ticket 

where 
(SitePendingLocation > 0 AND SitePendingLocation <> SiteCurrentLocation) AND 
(SiteCurrentLocation = @Current OR @Current = 0) AND 
(SitePendingLocation = @Pending OR @Current = 0) 
+1

您可以使用SET本身(無DECLARE)或使用_替換@(或無前綴)。有關類似問題,請參閱http://stackoverflow.com/questions/763718/whats-wrong-with-this-mysql-statement-declare-id-int。 – dash 2011-12-14 00:24:00

回答