sql - 必须在存储过程中声明标量变量 "@bit"作为输出参数

标签 sql sql-server database t-sql

我有这个程序,但是当它工作完美时,没有两个设置输出参数@bit的if。当我尝试执行 proc p3 时,出现以下错误

必须声明标量变量“@bit”。

这是代码

create proc p3 @codP int, @codM int, @dela datetime, @panala datetime, @pret smallint, @bit bit output
as
begin
    declare @val smallint
    set @val = (select COUNT(*)
                from OferteSpeciale as OS
                where OS.codP = @codP and OS.codM = @codM and 
                        ((@panala >= OS.dela and @panala <= OS.panala)
                        or (@dela >= OS.dela and @dela <= OS.panala) or
                        (@dela <= OS.dela and @panala >= OS.panala)))
    print @val
    if (@val = 0)
        begin
            insert into OferteSpeciale (codP,codM,dela,panala,pret) values (@codP,@codM,@dela,@panala,@pret)
            declare @others smallint
            set @others = (select COUNT(*)
                         from Cataloage as c, OferteSpeciale as os
                         where ((c.codM = @codM and c.codP = @codP and c.pret < @pret) or
                            (os.codM = @codM and os.codP = @codP and os.pret < @pret)))
            if (@others > 0)
              set @bit = 0
            else
              set @bit = 1
        end
    else
      RAISERROR 50001 'There is already a special offer for that product, in that shop, between that dates'
end
declare @bit bit
exec p3 1, 3, '2013-04-15', '2013-04-15', 25, @bit output

最佳答案

作为一个快速答案,在声明存储过程后,您缺少一个“GO”,如果我尝试按照您提供的方式运行它,我会收到一个不同的错误,如果我添加一个 GO 将声明从中分离出来,该错误就会消失执行。

end
GO
declare @bit bit
exec p3 1, 3, '2013-04-15', '2013-04-15', 25, @bit output

显然,我必须删除存储过程的内容,因为我的数据库中没有这些对象,但问题似乎与“@Bit”有关

关于sql - 必须在存储过程中声明标量变量 "@bit"作为输出参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15768555/

相关文章:

SQL Select : Update if exists, 如果没有则插入 - 与日期部分比较?

mysql - SQL语句问题

php - 与 mysql 的左连接问题

php - 连接两个表以获得计数

python - 使用 python 附加多个 db3 文件

Java NetBeans JDBC 连接在调试中工作,而不是在运行中

sql-server - 如何在 Linq to Entities 中进行多个内部联接

mysql - SQL Server 数据类型

java - 用户验证密码检查数据库

python - 如何在 Django 中实现多值属性?