locked
script for copying a column to another column of different table RRS feed

  • Question

  • User-1578974752 posted

    SQL command not properly ended error is showing while I run below code.Thanks in advance

    UPDATE T_CHARACTERISTICS
    SET T_CHARACTERISTICS.PROCESS = T_DOC.PROCESS
    FROM T_CHARACTERISTICS 
    JOIN  T_DOC ON T_CHARACTERISTICS.ID = T_DOC.ID

    Wednesday, December 6, 2017 1:30 AM

Answers

  • User2103319870 posted

    Tried your query like below and its working fine. Table is updated with values from TDOC table. Please provide the exact error message you get while runnning code

    using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SAMPLEDBConnectionString"].ConnectionString))
                {
                    con.Open();
                    //Insert QUery with Scope_Identity
                    using (SqlCommand cmd = new SqlCommand("UPDATE T_CHARACTERISTICS SET T_CHARACTERISTICS.PROCESS = T_DOC.PROCESS FROM T_CHARACTERISTICS JOIN  T_DOC ON T_CHARACTERISTICS.ID = T_DOC.ID; ", con))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.ExecuteScalar();
                    }
                }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 6, 2017 3:03 AM

All replies

  • User2103319870 posted

    Tried your query like below and its working fine. Table is updated with values from TDOC table. Please provide the exact error message you get while runnning code

    using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SAMPLEDBConnectionString"].ConnectionString))
                {
                    con.Open();
                    //Insert QUery with Scope_Identity
                    using (SqlCommand cmd = new SqlCommand("UPDATE T_CHARACTERISTICS SET T_CHARACTERISTICS.PROCESS = T_DOC.PROCESS FROM T_CHARACTERISTICS JOIN  T_DOC ON T_CHARACTERISTICS.ID = T_DOC.ID; ", con))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.ExecuteScalar();
                    }
                }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 6, 2017 3:03 AM
  • User-335504541 posted

    <g class="gr_ gr_9 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="9" data-gr-id="9">Hi</g> <g class="gr_ gr_10 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling" id="10" data-gr-id="10">shsu</g>,

    Are you using Oracle right?

    It seems Oracle does not allow joining tables in an UPDATE statement. You need to rewrite your statement with a co-related sub-select.

    For example:

    UPDATE T_CHARACTERISTICS 
    SET T_CHARACTERISTICS.PROCESS = (select T_DOC.PROCESS
    FROM T_CHARACTERISTICS  
    where T_CHARACTERISTICS.ID = T_DOC.ID)
    

    You could refer to the link below for more information:

    https://stackoverflow.com/questions/8940471/sql-error-ora-00933-sql-command-not-properly-ended

    Best Regards,

    Billy

    Thursday, December 7, 2017 10:00 AM