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

这个存储过程有问题吗?为什么print打印不出来值
SET QUOTED_IDENTIFIER OFF  
GO
SET ANSI_NULLS ON  
GO
ALTER PROCEDURE [dbo].[updateCjxm] AS
BEGIN

declare @name varchar(200)
declare @bzz varchar(200)
declare @jcz varchar(100)
declare @iguid varchar (200)
declare @str varchar(5000)

  DECLARE cjxmjg cursor for select [name],bzz,jcz,iguid from 抽检项目录入 where b271='不合格'
  OPEN cjxmjg
Fetch next from cjxmjg into @name,@bzz,@jcz,@iguid

WHILE @@FETCH_STATUS=0
begin
set @str=@name+':'+@bzz+'/'+@jcz;
print @str
begin
update 抽查结果信息表录入 set b28=@str where iguid=@iguid  
end
Fetch next from cjxmjg into @name,@bzz,@jcz,@iguid
  end

CLOSE cjxmjg
  DEALLOCATE cjxmjg
END
GO
SET QUOTED_IDENTIFIER OFF  
GO
SET ANSI_NULLS ON  
GO



------解决方案--------------------
你的語句沒發現問題

select [name],bzz,jcz,iguid from 抽检项目录入 where b271='不合格'--查看一下結果是否有 null
------解决方案--------------------
在 set @str=@name+':'+@bzz+'/'+@jcz; 位置打个断点 debug 下 看看 @str 有值没 可能你select 的字段数据类型与你定义的不一致
------解决方案--------------------
select @name+':'+@bzz+'/'+@jcz --把print改为 select 看看有没有值
------解决方案--------------------
SQL code

ALTER PROCEDURE [dbo].[updateCjxm]
AS 
    BEGIN

        DECLARE @name VARCHAR(200)
        DECLARE @bzz VARCHAR(200)
        DECLARE @jcz VARCHAR(100)
        DECLARE @iguid VARCHAR(200)
        DECLARE @str VARCHAR(5000)

        DECLARE cjxmjg CURSOR FOR 
        --这个里面有数据?
        SELECT [name],bzz,jcz,iguid FROM 抽检项目录入 WHERE b271='不合格'
        OPEN cjxmjg
        FETCH NEXT FROM cjxmjg INTO @name,@bzz,@jcz,@iguid

        WHILE @@FETCH_STATUS = 0 
            BEGIN
                SET @str = @name + ':' + @bzz + '/' + @jcz ;
                PRINT @str
                BEGIN
                    UPDATE  抽查结果信息表录入
                    SET     b28 = @str
                    WHERE   iguid = @iguid   
                END
                FETCH NEXT FROM cjxmjg INTO @name,@bzz,@jcz,@iguid
            END

        CLOSE cjxmjg
        DEALLOCATE cjxmjg
    END