我试图执行我的一个存储过程,但是我收到语法错误,我无法理解为什么。
这是sproc:
ALTER PROCEDURE [dbo].[HotlinePlusAdministration_ArticleMigrator]
@ArticleKey AS INT,
--@CategoryID AS INT,
--@Title AS Varchar(200),
--@ArticleDate AS datetime,
@DestLinkServer AS VARCHAR(50),
@UserID AS VARCHAR(8),
@ReturnMsg AS VARCHAR(1000) OUTPUT
AS
BEGIN
DECLARE @Query AS NVARCHAR(4000)
DECLARE @Log AS VARCHAR(8000)
DECLARE @ArticleID as int
DECLARE @NewArticleID as int
DECLARE @ArticleKeyExists as int
DECLARE @Title as varchar(200)
DECLARE @CategoryID as INT
DECLARE @ArticleDate as varchar(30)
DECLARE @ParmDefinition nvarchar(500);
SET XACT_ABORT ON -- Required for nested transaction
BEGIN TRAN
-- Check if ArticleID exists in Destination Server
SET @Query = N' SELECT @ArticleKeyExists = COUNT(*)
FROM ' + @DestLinkServer + '.HL2_61.dbo.Article' + ' where ArticleKey = ' + str(@ArticleKey)
SET @ParmDefinition = N'@ArticleKey int, @ArticleKeyExists int OUTPUT';
EXECUTE sp_executesql @Query , @ParmDefinition, @ArticleKey , @ArticleKeyExists OUTPUT;
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
SET @ReturnMsg = @Log + '<span style="color:red;">ERROR: <br></span>'
RETURN -1
END
--Delete existing Articles for select page
set @Query = 'DELETE FROM ' + @DestLinkServer +
'.HL2_61.dbo.Article ' +
'WHERE ArticleKey = ' + CONVERT(VARCHAR, @ArticleKey)
--'WHERE CategoryID = ' + CONVERT(VARCHAR, @CategoryID) + ' and Title = ''' + @Title + ''' and ArticleDate = ''' + @ArticleDate + ''''
Print @Query
EXEC(@Query)
当我尝试执行它时,我在这里收到错误:
SELECT @ArticleKeyExists = COUNT(*)
FROM BRWSQLDC.HL2_61.dbo.Article where ArticleKey = 1591276581
有些人可以帮我解决这个问题,
感谢。
答案 0 :(得分:1)
SET @ArticleKeyExists =(SELECT COUNT(*)FROM BRWSQLDC.HL2_61.dbo.Article where ArticleKey = 1591276581)