我在存储过程中声明了一个变量Declare @timecost as nvarchar(10)
我想在把一个表的查询结果赋给这个变量 select @timecost = (select top 1 timecost from record where email='pEmail@email' and status='1' order by timecost)
然后用这个变量update rank set timecost=@timecost where email='pEmail@email' 
存储过程中检测语法没有问题,可是在查询分析器中执行就报错了
服务器: 消息 208,级别 16,状态 1,过程 BestRecord,行 12
Invalid object name 'record '.
服务器: 消息 266,级别 16,状态 1,过程 BestRecord,行 25
Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 40, current count = 41.
'record '这个表明是存在的,单独执行select top 1 timecost from record where email='pEmail@email' and status='1' order by timecost这句也有结果,哪位大哥帮帮我啊

解决方案 »

  1.   


    CREATE PROCEDURE [dbo].[spBestRecord]
    @pEmail as nvarchar(50)
    AS
    SET NOCOUNT ON
    Declare @Rid as uniqueidentifier
    Declare @timecost as numeric(8)Begin Tran NEWRD
            select @Rid = (select top 1 grid from record where uemail=@pEmail and status='1' order by timecost)
            select @timecost = (select top 1 timecost from record where Sguemail=@pEmail and status='1' order by timecost)
            
            update rank set timecost=@timecost, rid=@Rid where uemail=@pEmail
                    
            IF @@ERROR>0 Goto Err
    Commit Tran NEWRD
        Select 0
        Return 0Err:
    ROLLBACK TRAN NEWRD
    Select -1
    Return -1
    GOrecord与rank表中的记录都已经存在 
    我在查询分析器中执行exex   spBestRecord   '[email protected] '就报了上面的错误
      

  2.   

    大哥,你这个是sql server的,不是db2的