SQL Query: Using Cursors
- by user2953138
I need some directions for SQL Server & Cursors:
I have a table named Order:
OrderID Item Amount
1 A 10
1 B 1
2 A 5
2 C 4
2 D 21
3 B 11
I have a second table named Storage:
Item Amount
A 40
B 44
C 20
D 1
For every OrderID, I want to check if enough items are available. If not, I want to return an error message. How can this be done with Cursors at all? Are nested cursors the solution to this? My main issue is to understand how I can fetch the OrderID as actual "Group" of ID=1, 2, 3 etc. instead of line by line