Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:30:24+00:00 2026-05-29T04:30:24+00:00

I am trying to insert ID values in stored procedure from .net and the

  • 0

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.

But when a negative value is passed its giving me an error incorrect syntax near ‘*’.

Please help me.

Here is my stored procedure

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 <> 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, @Id)
            --'WHERE CategoryID = ' + CONVERT(VARCHAR, @CategoryID)  + ' and Title = ''' + @Title + '''  and ArticleDate  = ''' + @ArticleDate  + ''''
Print @Query
EXEC(@Query)

When I am executing the code as below I am getting the error.

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

Please someone help me..

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:30:25+00:00Added an answer on May 29, 2026 at 4:30 am

    When you convert an int to a varchar, you have to specify the size:

    Try this:

    CONVERT(VARCHAR(50), @Id) 
    

    and avoid using str(@Id)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert a value to sql_variant column in sql server from
I am trying to insert a time only value, but get the following error
I'm trying to cache a price value using HttpRuntime.Cache.Insert(), but only appears to hold
What I'm trying to do is take the results from a stored procedure and
I am trying to return identity of last inserted row from a stored procedure.
I am trying to write a stored procedure that checks if a value exist,
I'm trying to port a stored procedure from MySQL to Oracle, and I'm having
I'm trying to write a stored procedure in which I insert a few things
I am trying to pass bulk values to my stored procedure using a data
I am trying to modify a stored procedure I wrote to pull data from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.