Question: I'm using SQL Server and have Management Studio installed if this is relevant.

I would like to copy a whole column from one table to another, but the catch is that the table I must copy to needs to be ordered a certain way, as there is no common identity between these tables I could use to join them.

I have read these two questions: 

* [Copy data from one column to other column (which is in a different table)](https://stackoverflow.com/questions/3361768/copy-data-from-one-column-to-other-column-which-is-in-a-different-table)
* [SQL Server: UPDATE a table by using ORDER BY](https://stackoverflow.com/questions/3439110/sql-server-update-a-table-by-using-order-by)

and I tried to combine their answers as follows:

```
WITH cte AS
(
    -- I must specify TOP to use ORDER BY
    SELECT TOP(50000) *
    FROM TableToCopyTo
    ORDER BY ColumnUsedToOrder
)
UPDATE cte 
SET ColumnToCopyTo = (SELECT ColumnToCopyFrom FROM TableToCopyFrom)

```

When I try to execute this query, it returns the following error:

> 
> Msg 512, Level 16, State 1, Line 1  
> 
>  Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
> 
> 
> 

I've tried looking up the error but couldn't find relevant information.

I would like to either understand why my query is wrong or find an alternative to achieve what I'm looking for.

Answer: 
**Hope this will help you :**

For 500 error check u calling the correct controller's method which in turn call `edit_parameter` method

it should work unless `$table` is empty;

check `$table` first for not `empty`

```
  function edit_parameter($description,$code,$table)
  {
    if (!empty($table))
    {
       $param=array('description'=>$description);
       $this->db->where('code', $code);
       if (! $this->db->update($table,$param)) {
          return $this->db->error();
       }

    }
    else
   {
       $status = 'table not found !';
       return $status;
   }

}

```
Try this, I hope it's working 

```
function edit_parameter($description, $code, $table = null) {
    if ($table == null || !is_string($table)) return;

    $param = array(
        'description' => $description
    );
    $this->db->where('code', $code);
    if(!$this->db->update($table, $param)) {
        return $this->db->error();
    }
}

```