mysql declare 语法_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。 –

2011-12-14 00:24:00

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值