我有如下存储过程逻辑。我得到了
关键字'set'附近的语法不正确。
错误,请告诉我解决方案。
Declare @VAL int
Declare @Region bigint
drop table Tempqq
Select * Into Tempqq From dbo.split(@SpokeFolderList, ',')
while (Select Count(*) From Tempqq) > 0
begin
Select Top 1 @VAL = Tempqq.val From Tempqq
;With MyCount AS
(
Select DispatchToRegionId ,FolderNo, row_number() OVER(ORDER BY FolderNo DESC) as Row
from tblTransite where FolderNo = @VAL group by DispatchToRegionId,FolderNo
)
set @Region =( Select top 1 DispatchToRegionId from MyCount
order by Row desc )
print @VAL
Delete Tempqq Where Tempqq.val = @VAL
end
答案 0 :(得分:1)
试试这个
Declare @VAL int
Declare @Region bigint
drop table Tempqq
Select * Into Tempqq From dbo.split(@SpokeFolderList, ',')
while (Select Count(*) From Tempqq) > 0
begin
Select Top 1 @VAL = Tempqq.val From Tempqq
;With MyCount AS
(
Select DispatchToRegionId ,FolderNo, row_number() OVER(ORDER BY FolderNo DESC) as Row
from tblTransite where FolderNo = @VAL group by DispatchToRegionId,FolderNo
)
Select top 1 DispatchToRegionId into @Region from MyCount
order by Row desc
print @VAL
Delete Tempqq Where Tempqq.val = @VAL
end
答案 1 :(得分:0)
CTE更像是VIEW而不是存储过程。它没有 似乎是正确的语法。
Delete
应该有一个From
关键字
试试这个
Declare @VAL int
Declare @Region bigint
Drop table Tempqq
Select * Into Tempqq From dbo.split(@SpokeFolderList, ',')
While (Select Count(*) From Tempqq) > 0
Begin
Select Top 1 @VAL = Tempqq.val From Tempqq
;With MyCount AS
(
Select DispatchToRegionId ,FolderNo, row_number() OVER(ORDER BY FolderNo DESC) as Row
From tblTransite where FolderNo = @VAL group by DispatchToRegionId,FolderNo
)
Select @Region =(Select top 1 DispatchToRegionId from MyCount order by Row desc)
Print @VAL
Delete From Tempqq Where Tempqq.val = @VAL
End