我正在使用 sqsh 执行存储过程:
我简化了这样的过程,以便您更容易阅读:
CREATE PROCEDURE MyProc
AS
BEGIN
SELECT *
FROM Keys
WHERE 1=1
;WITH CTE AS
(
SELECT TOP 1 *
FROM MyTableName
ORDER BY CreationTime ASC
)
SELECT *
FROM CTE
END
;
go
我得到的错误是这样的:
Use: \go [-d display] [-h] [-f] [-n] [-p] [-m mode] [-s sec]
[-t [filter]] [-w width] [-x [xgeom]] [-T title] [xacts]
-d display When used with -x, send result to named display
-h Suppress headers
-f Suppress footers
-n Do not expand variables
-p Report runtime statistics
-m mode Switch display mode for result set
-s sec Sleep sec seconds between transactions
-t [filter] Filter SQL through program
Optional filter value overrides default variable $filter_prog
-w width Override value of $width
-x [xgeom] Send result set to a XWin output window
Optional xgeom value overrides default variable $xgeom
-T title Used in conjunction with -x to set window title
xacts Repeat batch xacts times
Msg 156, Level 15, State 1
Server 'myServer', Procedure 'MyProc', Line xx
Incorrect syntax near the keyword 'ORDER'.
这是未简化的版本:
CREATE PROCEDURE [dbo].[MyCustomProcedure]
@BatchSize INT WITH ENCRYPTION
AS
BEGIN
DECLARE @CurrentName varchar(max)
SET @CurrentName = [dbo].[GetCurrentyName]()
DECLARE @CurrentID INT
SELECT @CurrentID=ID FROM [dbo].[Keys] WHERE OriginalName = @CurrentName
;WITH CTE AS
(
SELECT TOP (@BatchSize) *
FROM [dbo].[SerialNumbers]
WHERE ID <> @CurrentID
ORDER BY CreationTime ASC
)
UPDATE CTE
SET EncodedSerial = (Encode(Key_GUID(@CurrentName), CONVERT(VARCHAR,(Decode(EncodedSerial))))),
ID=@CurrentID
END
;
go
我已经看过其他类似的问题。我找不到语法有什么问题,还能是什么?SQLServer 版本?