日期:2014-05-19  浏览次数:20398 次

帮忙看看这段sql执行没效果?
use   whinfo2004

DECLARE   @txxid   int,@personid   int,@lxfs   int

DECLARE       authors_cursor       CURSOR       FOR        
SELECT   id,personid,lxfsid
FROM   dbo.scl_txx
WHERE   (personid   <>   -   1)

OPEN       authors_cursor    

FETCH       NEXT       FROM       authors_cursor        
INTO       @txxid,       @personid,       @lxfs    
--按理说这里不需要加这段处理,但是不加就执行不过去
print   @txxid
if   (@lxfs=null)
BEGIN
update   dbo.scl_txx   set   lxfsid= '-1 '
where   id=@txxid
END
----
WHILE   (@@FETCH_STATUS       =       0     )

BEGIN    
FETCH       NEXT       FROM       authors_cursor        
INTO       @txxid,       @personid,       @lxfs    

print   @txxid

IF   (@lxfs=null)
BEGIN
UPDATE   dbo.scl_txx   SET   lxfsid=-1
WHERE   id=@txxid
END

END    

在sql2005SP2环境下,执行成功,但是数据并没发生变化,高手看看那里出错了,谢谢!

------解决方案--------------------
if (@lxfs is null)
------解决方案--------------------
print @txxid
if (@lxfs=null)
BEGIN
update dbo.scl_txx set lxfsid= '-1 '
where id=@txxid
END

以上放在WHILE (@@FETCH_STATUS = 0 )之后
------解决方案--------------------
問題錯在這里:
將if (@lxfs=null)改為if (@lxfs is null)

DECLARE @NULL VARCHAR(10)
SET @NULL = NULL

IF (@NULL IS NULL)
PRINT 'IS NULL '
ELSE
PRINT 'NOT NULL '+@NULL
------解决方案--------------------
use whinfo2004
GO
DECLARE @txxid int,@personid int,@lxfs int

DECLARE authors_cursor CURSOR FOR
SELECT id,personid,lxfsid
FROM dbo.scl_txx
WHERE (personid <> - 1)

OPEN authors_cursor

FETCH NEXT FROM authors_cursor
INTO @txxid, @personid, @lxfs

WHILE (@@FETCH_STATUS=0)
BEGIN
if (@lxfs IS null)
BEGIN
update dbo.scl_txx set lxfsid= '-1 '
where id=@txxid
END

IF (@lxfs IS null)
BEGIN
UPDATE dbo.scl_txx SET lxfsid=-1
WHERE id=@txxid
END

FETCH NEXT FROM authors_cursor
INTO @txxid, @personid, @lxfs
END
CLOSE authors_cursor
DEALLOCATE authors_cursor