I am trying to return the value of a column if a condition is met:

cmd.CommandText = "SELECT plan_entity_id FROM PLANNER_INFO Where plan_id = plan_id";
                cmd.Parameters.Add("plan_id", SqlDbType.Int, value);
               
                con.Open();
                returnValue = Convert.ToInt32(cmd.ExecuteScalar());

for instance, if Plan_id is 1 it returns the entity ID which is equals to 1.
if Plan_id = 5, the fifth row in the table. But it returns the value for 1 which is the first row (that is, plan_id = 1).
How do I fix this please?
Thanks

The where condition of your query is wrong. Use: Where plan_id = [B]@plan_id[/B] And: cmd.Parameters.Add("@plan_id", SqlDbType.Int, value);