Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. SET NOCOUNT ON;
  2.  
  3. DECLARE @vendor_id int, @vendor_name nvarchar(50),
  4. @message varchar(80), @product nvarchar(50);
  5.  
  6. PRINT '-------- Vendor Products Report --------';
  7.  
  8. DECLARE vendor_cursor CURSOR FOR
  9. SELECT VendorID, Name
  10. FROM Purchasing.Vendor
  11. WHERE PreferredVendorStatus = 1
  12. ORDER BY VendorID;
  13.  
  14. OPEN vendor_cursor
  15.  
  16. FETCH NEXT FROM vendor_cursor
  17. INTO @vendor_id, @vendor_name
  18.  
  19. WHILE @@FETCH_STATUS = 0
  20. BEGIN
  21. PRINT ' '
  22. SELECT @message = '----- Products From Vendor: ' +
  23. @vendor_name
  24.  
  25. PRINT @message
  26.  
  27. -- Declare an inner cursor based
  28. -- on vendor_id from the outer cursor.
  29.  
  30. DECLARE product_cursor CURSOR FOR
  31. SELECT v.Name
  32. FROM Purchasing.ProductVendor pv, Production.Product v
  33. WHERE pv.ProductID = v.ProductID AND
  34. pv.VendorID = @vendor_id -- Variable value from the outer cursor
  35.  
  36. OPEN product_cursor
  37. FETCH NEXT FROM product_cursor INTO @product
  38.  
  39. IF @@FETCH_STATUS <> 0
  40. PRINT ' <<None>>'
  41.  
  42. WHILE @@FETCH_STATUS = 0
  43. BEGIN
  44.  
  45. SELECT @message = ' ' + @product
  46. PRINT @message
  47. FETCH NEXT FROM product_cursor INTO @product
  48. END
  49.  
  50. CLOSE product_cursor
  51. DEALLOCATE product_cursor
  52. -- Get the next vendor.
  53. FETCH NEXT FROM vendor_cursor
  54. INTO @vendor_id, @vendor_name
  55. END
  56. CLOSE vendor_cursor;
  57. DEALLOCATE vendor_cursor;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement