I have three tables:
ORSeries
where the last official receipt is temporarily saved:
|ORSeries|
+--------+
| 1000 |
Collections
where users issued with an official receipt will be saved:
| OR | ID | Date |
+--------+--------+--------+
| | | |
Users
where users without an official receipt are saved:
| ID | Date |
+--------+------------+
| 0001 | 08-10-2019 |
| 0002 | 08-10-2019 |
| 0003 | 08-10-2018 |
| 0004 | 08-10-2018 |
| 0005 | 08-10-2018 |
I want to issue an official receipt to the users dated 08-10-2018. What I have so far:
INSERT INTO [Collections] (OR, Name, [Date])
SELECT
(SELECT SeriesNo + 1 FROM TempORSeries),
Name,
[Date]
FROM
ORSeries
Expected output:
| OR | ID | Date |
+--------+--------+------------+
| 10001 | 0003 | 08-10-2018 |
| 10002 | 0004 | 08-10-2018 |
| 10003 | 0005 | 08-10-2018 |
However, all the users received the same official receipt number.
My query returns:
| OR | ID | Date |
+--------+--------+------------+
| 10001 | 0003 | 08-10-2018 |
| 10001 | 0004 | 08-10-2018 |
| 10001 | 0005 | 08-10-2018 |
How can I fix this?