SQL 2008 年的存储过程在 2005 年不工作
Stored Procedure in SQL 2008 Not Working in 2005
您好,我正在尝试在 SQL2005 中创建存储过程,下面是我的语法
CREATE PROCEDURE [dbo].[POBalance] @PONumber nvarchar(50)
AS BEGIN
declare @status bit = (Select status from tblPOHeader where PONo = @PONumber )
if @status = 'False'
Select
A.Description,
C.qty as POqty,
B.QtyDelivered as PDQty,
case when A.partialflag ='false'
then '0'
else
A.qty end as Balance,
A.Unit,
A.Unitprice,
A.Partialflag
from tblPOdetails as A
Inner Join ( SELECT id, SUM(Qty) AS QtyDelivered
FROM dbo.tblPDdetails
WHERE (PONo = @PONumber)
GROUP BY id)as B On A.id = B.id
Inner Join tblpodetailshistory as C on A.id =C.id
where A.PONo = @PONumber
ELSE
Select
A.Description,
C.qty as POqty,
B.QtyDelivered as PDQty,
'0' as Balance,
A.Unit,
A.Unitprice,
A.Partialflag
from tblPOdetails as A
Inner Join ( SELECT id, SUM(Qty) AS QtyDelivered
FROM dbo.tblPDdetails
WHERE (PONo = @PONumber)
GROUP BY id)as B On A.id = B.id
Inner Join tblpodetailshistory as C on A.id =C.id
where A.PONo = @PONumber
END
当我执行时,我遇到了这个错误。
Msg 102, Level 15, State 1, Procedure POBalance, Line 13
Incorrect syntax near '('.
Msg 137, Level 15, State 2, Procedure POBalance, Line 14
Must declare the scalar variable "@status".
Msg 156, Level 15, State 1, Procedure POBalance, Line 36
Incorrect syntax near the keyword 'ELSE'.
但该语法已在 SQL2008 中运行,没有问题。我想知道 2005 年和 2008 年之间是否有不同的语法..
有没有人知道这个。
谢谢!
在 T-SQL 兼容版本 90 (SQL SERVER 2005) 中,您不能在 DECALRE
语句 (DOC) 中赋值。
这应该有效:
declare @status bit
set @status = (Select status from tblPOHeader where PONo = @PONumber )
if @status = 'False'
您好,我正在尝试在 SQL2005 中创建存储过程,下面是我的语法
CREATE PROCEDURE [dbo].[POBalance] @PONumber nvarchar(50)
AS BEGIN
declare @status bit = (Select status from tblPOHeader where PONo = @PONumber )
if @status = 'False'
Select
A.Description,
C.qty as POqty,
B.QtyDelivered as PDQty,
case when A.partialflag ='false'
then '0'
else
A.qty end as Balance,
A.Unit,
A.Unitprice,
A.Partialflag
from tblPOdetails as A
Inner Join ( SELECT id, SUM(Qty) AS QtyDelivered
FROM dbo.tblPDdetails
WHERE (PONo = @PONumber)
GROUP BY id)as B On A.id = B.id
Inner Join tblpodetailshistory as C on A.id =C.id
where A.PONo = @PONumber
ELSE
Select
A.Description,
C.qty as POqty,
B.QtyDelivered as PDQty,
'0' as Balance,
A.Unit,
A.Unitprice,
A.Partialflag
from tblPOdetails as A
Inner Join ( SELECT id, SUM(Qty) AS QtyDelivered
FROM dbo.tblPDdetails
WHERE (PONo = @PONumber)
GROUP BY id)as B On A.id = B.id
Inner Join tblpodetailshistory as C on A.id =C.id
where A.PONo = @PONumber
END
当我执行时,我遇到了这个错误。
Msg 102, Level 15, State 1, Procedure POBalance, Line 13
Incorrect syntax near '('.
Msg 137, Level 15, State 2, Procedure POBalance, Line 14
Must declare the scalar variable "@status".
Msg 156, Level 15, State 1, Procedure POBalance, Line 36
Incorrect syntax near the keyword 'ELSE'.
但该语法已在 SQL2008 中运行,没有问题。我想知道 2005 年和 2008 年之间是否有不同的语法..
有没有人知道这个。
谢谢!
在 T-SQL 兼容版本 90 (SQL SERVER 2005) 中,您不能在 DECALRE
语句 (DOC) 中赋值。
这应该有效:
declare @status bit
set @status = (Select status from tblPOHeader where PONo = @PONumber )
if @status = 'False'