SQL Query: Using Cursors

Posted by user2953138 on Stack Overflow See other posts from Stack Overflow or by user2953138
Published on 2013-11-04T15:51:09Z Indexed on 2013/11/04 15:53 UTC
Read the original article Hit count: 248

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about sql

Related posts about cursors