Postman collection
Customers Write

pixiSetCustomerDiscount

Sets the discount percentage (`Rabat`) of one customer identified by e-mail address and/or external customer number.

Updates the field Rabat of exactly one customer in Customers and returns a status row.

Validation

  • Discount is mandatory and must be between 0 and 100, inclusive.
  • Empty strings in CustMail and CustNr are treated as NULL. At least one of them must be supplied.

Customer lookup

The procedure counts customers matching CeMail = CustMail, customers matching CustomerNrExternal = CustNr, and customers matching both. If CustNr is not supplied, the last check only requires a matching e-mail and a non-NULL customer number. The customer is then chosen as follows:

  1. If exactly one customer has the e-mail address, that customer is used. CustNr is ignored in this case.
  2. If no customer has the e-mail address and exactly one customer has the customer number, that customer is used.
  3. If several customers share the e-mail address and exactly one of them matches the customer number, that one is used.
  4. Otherwise an error row is returned. The message is either More then one customer found… or No customer found….

Update and result

The procedure sets Rabat to Discount for the chosen customer. It then returns one row with Status = Success and a message containing the new discount, the customer's e-mail address and the external customer number. Every error, including validation errors, is returned as a single row with Status = Error and the error text in Message.

Notes

  • Errors never arrive as SqlMessage. They are caught and returned as a row with Status = Error, so always check the Status column.
  • Pitfall: if the e-mail address matches exactly one customer, that customer is updated even when the supplied CustNr belongs to a different customer or matches no customer.
  • The success message is built by string concatenation. If the customer's CeMail or CustomerNrExternal is NULL, Message is likely to be NULL (the usual SQL Server behaviour with CONCAT_NULL_YIELDS_NULL), although the update has been done.
  • Lookups use NOLOCK and the update uses ROWLOCK. No explicit transaction is used.
  • E-mail and customer number are compared with =. Whether the comparison is case-sensitive depends on the database collation.

Tables used

Customers · Write
SQL object:
dbo.pipiSetCustomerDiscount
Updated at 2026-10-30