3
I have a query where I have a SELECT from a client ID, and an order ID. Later I perform an UPDATE in a table, changing the tax rate on the selected order.
The problem is that a customer may have multiple orders. When I place several order Ids.... But how can I actually do a query to update these multiple entries?
Here I have the SELECT:
SELECT
p.idPedido,
c.nome,
p.dataPagamento,
p.valor,
p.taxaImposto
FROM
Pedidos p
JOIN Clientes c ON (c.id = p.idCliente)
WHERE
c.id IN ({txtClienteId.Text})
AND
p.idPedido IN ({txtPedidoId.Text})
And here the update:
UPDATE
Pedidos
SET
taxaImposto = @taxa
WHERE
idPedido = @idPedido
AND
idCliente = @idCliente;
cmd.Parameters.Add("@taxa", SqlDbType.Float).Value = Convert.ToDouble(txtTaxaImposto.Text);
cmd.Parameters.Add("@idPedido", SqlDbType.BigInt).Value = Convert.ToInt32(txtPedidoId.Text);
cmd.Parameters.Add("@idCliente", SqlDbType.BigInt).Value = Convert.ToInt32(txtClienteId.Text);
UPDATE works normally when I only have one entry in the Orders ID, but I want to make it possible to update to multiple entries, from the same customer, that is, insert a customer ID, a Fee, and n Orders ID’s.
All records of the interval
WHERE c.id IN ({txtClienteId.Text}) AND p.idPedido IN ({txtPedidoId.Text})
will have the same rate?– João Martins
Yes, the fee will be the same for all selected orders
– InFilterside
There is selection of customers and/or orders to make the
UPDATE
? Or all who were returned bySELECT
will be updated?– João Martins
The user will enter the customer ID, the fee, and 1 or multiple orders, and the orders will always be for the same customer.
– InFilterside