日期:2014-05-18  浏览次数:20422 次

我很惭愧,问这么简单的问题!!!!!!!!!!!!!!!!!
CREATE   PROCEDURE   BuyMessage
(
        @recordid   INT,
        @buyid   INT,
        @sorb   INT,
        @sellid   INT   OUTPUT,
        @result   INT   OUT
)
AS
if   @sorb=0
        SELECT         @sellid=BuyId
        FROM   BuyM_View
        WHERE   RecordId=@recordid   AND   SellId=@buyid  
else   if   @sorb=1
        SELECT   @sellid=SellId
        FROM     SellM_View
        WHERE   RecordId=@recordid   AND     BuyId=@buyid

IF   @@ROWCOUNT   > =   1
      SELECT   @result=1
ELSE  
      SELECT   @result=0
GO
====================================================
以上存储过程的IF   @@ROWCOUNT   > =   1,我想用他来检查上面的语句是否执行过,执行过则令@result=1,否则@result=0.但是不知道怎么的每次我测试他都是@result=0.不知道何故?是不是IF   @@ROWCOUNT   > =   1的问题呢?注意上面用到了if   else   if的判断

------解决方案--------------------
declare @iCount int
if @sorb=0
begin
set @iCount =(SELECT count(*) FROM BuyM_View WHERE RecordId=@recordid AND SellId=@buyid )
SELECT @sellid=BuyId FROM BuyM_View WHERE RecordId=@recordid AND SellId=@buyid
end
else if @sorb=1
begin
set @iCount =(SELECT count(*) FROM BuyM_View WHERE RecordId=@recordid AND BuyId=@buyid )

SELECT @sellid=SellId FROM SellM_View WHERE RecordId=@recordid AND BuyId=@buyid
end

IF @iCount > = 1
SELECT @result=1
ELSE
SELECT @result=0
GO

------解决方案--------------------
也可以这样啊,两句合成一句:
SELECT @sellid=SellId,@iCount=count(*) FROM SellM_View WHERE RecordId=@recordid AND BuyId=@buyid
------解决方案--------------------
看了楼主的问题,我更惭愧。自愧不如。
楼主,请教两个问题,@@ROWCOUNT是不是返回当前所指表中的行数?
为什么在参数设置中第一个是OUTPUT来表示,最后一个参数用的却是OUT?
谢谢!
------解决方案--------------------

IF @sellid is null --@@ROWCOUNT > = 1
SELECT @result=0
ELSE
SELECT @result=1