title: Passing negative values into stored procedure
body: <p>I am trying to insert ID values in stored procedure from .net and the int value for ID is inserting negative value in the stored procedure.</p>
  
  <p>But when a negative value is passed its giving me an error incorrect syntax near '*'.</p>
  
  <p>Please help me.</p>
  
  <p>Here is my stored procedure </p>
  
  <pre><code>ALTER PROCEDURE [dbo].[HotlinePlusAdministration_ArticleMigrator]
          @Id 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(@Id)
  
          SET @ParmDefinition =  N' @ID int, @ArticleKeyExists int OUTPUT';
  
          EXECUTE sp_executesql @Query , @ParmDefinition, @ID, @ArticleKeyExists  OUTPUT;
  --EXECUTE sp_executesql 1234,'BRHLSQL8','BRWSQLDC',@return = retnmsg
  
                       IF @@ERROR &lt;&gt; 0
                           BEGIN 
                                   ROLLBACK TRANSACTION
                              SET @ReturnMsg = @Log + '&lt;span style="color:red;"&gt;ERROR: &lt;br&gt;&lt;/span&gt;'
                                  RETURN -1
                          END
  
  
  --Delete existing Articles for select page
  set @Query = 'DELETE FROM ' + @DestLinkServer + 
              '.HL2_61.dbo.Article ' +
               'WHERE ArticleKey = ' + CONVERT(VARCHAR, @Id)
              --'WHERE CategoryID = ' + CONVERT(VARCHAR, @CategoryID)  + ' and Title = ''' + @Title + '''  and ArticleDate  = ''' + @ArticleDate  + ''''
  Print @Query
  EXEC(@Query)
  </code></pre>
  
  <p>When I am executing the code as below I am getting the error.</p>
  
  <pre><code>DECLARE @return_value int,
          @ReturnMsg varchar(1000)
  
  EXEC    @return_value = [dbo].[Migrator]
          @Id = -1591276581,
          @DestLinkServer = N'SQLDC',
          @UserID = N'10c1',
          @ReturnMsg = @ReturnMsg OUTPUT
  
  SELECT  @ReturnMsg as N'@ReturnMsg'
  
  SELECT  'Return Value' = @return_value
  
  GO
  </code></pre>
  
  <p>Please someone help me..</p>
  
  <p>Thanks</p>