我把一些报告,从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。 –
2011-12-14 00:24:00