I would like to create a stored procedure. I have 2 databases - one with customers' data and the second one with discount codes. I would like to assign code to each customer. The code can be assigned only once, so I would like to mark the code as 'used' once it is assigned. The codes should be assigned only to those customers that don't have a code assigned.

CUSTOMER\_DATABASE:

| CUSTOMER ID | CUSTOMER CODE |
| --- | --- |
| 1 | 6f73js |
| 2 |  |
| ... | ... |

DATA\_DISCOUNT\_CODES:

| ID | CODE | STATUS |
| --- | --- | --- |
| 1 | 6f73js | USED |
| 2 | kdw45s |  |
| ... | ... | ... |

Is it possible to use INSERT INTO and UPDATE in one query? I tried to do this like that, but something is not working. The status changes to 'used' but the codes don't assign.

```
INSERT INTO CUSTOMERS_DATABASE (CUSTOMER CODE)
SELECT CODE FROM DATA_DISCOUNT_CODES
WHERE STATUS = ''
UPDATE DATA_DISCOUNT_CODES 
SET STATUS = 'Used';

```

Could you please help me write the query?