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 8374685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:58:36+00:00 2026-06-09T14:58:36+00:00

I currently have an update statement running in c# and the front end to

  • 0

I currently have an update statement running in c# and the front end to edit some values in my sql server database. But I am getting a Conversion Failed error. I can not seem to find the source.

ERROR message

Conversion failed when converting the nvarchar value 'UPDATE T_ROLLUP_SYSTEM_EXCEPT
            SET DEPT_ID = ' to data type int.
14

Sql

ALTER PROCEDURE [dbo].[USP_UPDATE_SYS_MAPPING]
-- Add the parameters for the stored procedure here
@SYSTEM VARCHAR(50),
@UNIT VARCHAR(50),
@MEDCTRLEVEL VARCHAR(50),
@MEDCTR VARCHAR(50),
@FACID VARCHAR(50),
@ENTN VARCHAR(50),
@DEPT_ID INT,
@ROLLUP_TYPE_ID INT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @SQL VARCHAR(MAX);
DECLARE @MEDCTRID INT;

SELECT @MEDCTRID = MED_CTR_ID FROM T_ROLLUP_MED_CTR WHERE MED_CTR = @MEDCTR
PRINT (@MEDCTRID);

-- Insert statements for procedure here
SET @SQL = N'UPDATE T_ROLLUP_SYSTEM_EXCEPT
            SET DEPT_ID = 
                '''+@DEPT_ID'''                 , ROLLUP_TYPE_ID = '''+@ROLLUP_TYPE_ID+'''
                , UPDATE_DT = GETDATE()
            WHERE SYSTEM = '''+@SYSTEM+'''
                AND ENTN = '''+@ENTN+'''
                AND MED_CTR_ID = '+CONVERT(VARCHAR,@MEDCTRID)+'
                AND MED_CTR_LEVEL = '''+@MEDCTRLEVEL+'''
                AND FAC_ID = '''+@FACID+'''
                AND UNIT = '''+@UNIT+''''
PRINT (@SQL);
EXEC (@SQL);

HTML

            string[] mdctrvalue = medctr.Text.Split('[', ']');
            string[] mpvalue = mpSearch.Text.Split('(', ')');

            string sys = acctsys.ToString();
            string unit = txtunit.ToString();
            string mdctrlvl = mdctrvalue[1].ToString();
            string mdctr = mdctrvalue[0].ToString();
            string facid = fac.ToString();
            string entn = txtentn.ToString();
            string dept_id = dept.SelectedValue.ToString();
            string rollup_type_id = rolluptype.SelectedValue.ToString();

            SqlConnection myconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Rollup2ConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = myconn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "USP_UPDATE_SYS_MAPPING";
            cmd.Parameters.Add("@SYSTEM", SqlDbType.VarChar).Value = acctsys.ToString();
            cmd.Parameters.Add("@UNIT", SqlDbType.VarChar).Value = unit.ToString();
            cmd.Parameters.Add("@MEDCTRLEVEL", SqlDbType.VarChar).Value = mdctrlvl.ToString();
            cmd.Parameters.Add("@MEDCTR", SqlDbType.VarChar).Value = mdctr.ToString();
            cmd.Parameters.Add("@FACID", SqlDbType.VarChar).Value = facid.ToString();
            cmd.Parameters.Add("@ENTN", SqlDbType.VarChar).Value = entn.ToString();
            cmd.Parameters.Add("@DEPT_ID", SqlDbType.Int).Value = dept_id.ToString();
            cmd.Parameters.Add("@ROLLUP_TYPE_ID", SqlDbType.Int).Value = rollup_type_id.ToString();

            myconn.Open();
            int retVal = cmd.ExecuteNonQuery();
  • 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-06-09T14:58:38+00:00Added an answer on June 9, 2026 at 2:58 pm

    Maybe change:

    +@ROLLUP_TYPE_ID+
    

    To:

    + CONVERT(VARCHAR(12), @ROLLUP_TYPE_ID) +
    

    You should always specify a length for your varchar columns/variables…

    That said, you can re-write your stored procedure to not use dynamic SQL at all – why is it being used?

    ALTER PROCEDURE [dbo].[USP_UPDATE_SYS_MAPPING]
      @SYSTEM         VARCHAR(50),
      @UNIT           VARCHAR(50),
      @MEDCTRLEVEL    VARCHAR(50),
      @MEDCTR         VARCHAR(50),
      @FACID          VARCHAR(50),
      @ENTN           VARCHAR(50),
      @DEPT_ID        INT,
      @ROLLUP_TYPE_ID INT
    AS
    BEGIN
      SET NOCOUNT ON;
    
      DECLARE @MEDCTRID INT;
    
      SELECT @MEDCTRID = MED_CTR_ID FROM dbo.T_ROLLUP_MED_CTR 
        WHERE MED_CTR = @MEDCTR;
    
      PRINT (@MEDCTRID);
    
      UPDATE dbo.T_ROLLUP_SYSTEM_EXCEPT
        SET DEPT_ID = CASE 
          WHEN @DEPT_ID > 1 THEN @DEPT_ID 
          WHEN @DEPT_ID = 1 THEN NULL 
          ELSE REG_DEPT_ID1 END 
         , ROLLUP_TYPE_ID = @ROLLUP_TYPE_ID
         , UPDATE_DT = GETDATE()
        WHERE SYSTEM = @SYSTEM
        AND ENTN = @ENTN
        AND MED_CTR_ID = @MEDCTRID
        AND MED_CTR_LEVEL = @MEDCTRLEVEL
        AND FAC_ID = @FACID
        AND UNIT = @UNIT;
    END
    GO
    

    If it needs to be dynamic SQL for some reason you haven’t yet shared, you are still better off parameterizing as much of this as possible using sp_executesql instead of EXEC().

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

Sidebar

Related Questions

I am currently running the following SQL statement on my MySQL database: INSERT INTO
I currently have a problem attepting to update a record within my database. I
I have a common field in a database table on SQL Server 2008. The
I am getting this error when running a save insert/update command: SEVERE: null java.sql.SQLIntegrityConstraintViolationException:
I have a VB6 application which works with datetime values in SQL Server (which
Running the following query in SQL Server Management Studio gives the error below. update
I have a mysql database that is currently running very slow. There are a
I currently have a list of things to update in the given mysqli query:
I currently have version 5.2.37 and I want to update to 5.2.38. How do
Currently I have to write the following to update an element already contained in

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.