我已经在脚本下面了,但是当我尝试执行它时,请在下面给出错误 -
Msg 102,Level 15,State 1,Line 6'='附近的语法不正确。
declare @PostDate date
declare @PostID int
DECLARE @count INT
DECLARE @updatecounter INT
WHILE exists (select top 1 @PostDate = postdate from dateTemp order by postdate desc)
BEGIN
PRINT @PostDate
SELECT @count = COUNT(*) from cs_posts_bkup20160209 where CONVERT(date,Postdate) = @PostDate
print @COUNT
SET @updatecounter = 1
WHILE (@count>=1)
BEGIN
select top 1 @PostID = PostId from cs_posts_bkup20160209 where CONVERT(date,Postdate) = @PostDate and Postorder IS NULL order by postdate desc
pRINT @POSTID
--update cs_posts_bkup20160209 set PostOrder = @updatecounter where postid= @PostID
SET @updatecounter = @updatecounter + 1
SET @count = @count - 1
Print @updatecounter
Print @count
END
DELETE from dateTemp where Postdate = @PostDate
END
GO
我在这里失踪了......
请帮助!!
答案 0 :(得分:1)
如果在select中指定变量,则select也不会返回结果集 - EXISTS
需要结果集。
最简单的修复可能是重新运行在循环中设置@PostDate
的查询,并从while循环使用的查询中删除赋值。