2012-01-31 116 views
0

我試圖執行我的一個存儲過程,但出現語法錯誤,我無法理解爲什麼。'*'附近的語法不正確

這裏是存儲過程:

ALTER PROCEDURE [dbo].[HotlinePlusAdministration_ArticleMigrator] 
      @ArticleKey AS INT, 
      [email protected] AS INT, 
      [email protected] AS Varchar(200), 
      [email protected] 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

什麼是你想用@ArticleKeyExists = COUNT(*)怎麼辦? – zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 2012-01-31 17:27:05

+0

我想檢查鏈接的服務器是否具有該值init,如果是這樣我將刪除該行並插入新的值,我試圖發送 – user1005479 2012-01-31 17:56:30

回答

1

SET @ArticleKeyExists =(SELECT COUNT(*)FROM BRWSQLDC.HL2_61.dbo.Article其中ArticleKey = 1591276581)

+0

我剛剛測試了這個,它的工作原理... – emalamisura 2012-01-31 17:29:51

+0

+1是的,你可以不要忽略SELECT部分​​,並自己使用COUNT作爲記錄集。 – 2012-01-31 18:54:26