Advertisement
ayurchyk1998

lab3.20316

Nov 1st, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.82 KB | None | 0 0
  1. --4 zad--
  2.  
  3. IF EXISTS (SELECT * FROM sys.procedures WHERE name= 'ProductAdd' AND type='P')
  4.     DROP PROCEDURE [dbo].[ProductAdd]
  5. GO
  6.  
  7. Create procedure dbo.ProductAdd
  8.     @productname nvarchar(20) = NULL,
  9.     @categoryname nvarchar(20) = NULL,
  10.     @unitprice money = NULL,
  11.     @suppliername nvarchar(20) = NULL
  12. AS
  13. set nocount on;
  14. IF EXISTS (SELECT productname FROM Production.Products WHERE @productname = productname)
  15.     PRINT 'Już istnieje produkt o takiej nazwie'
  16. ELSE
  17.     BEGIN
  18.         INSERT INTO Production.Products (productname,supplierid,categoryid, unitprice)
  19.         VALUES (@productname,
  20.                 (SELECT supplierid FROM Production.Suppliers WHERE companyname = @suppliername ),
  21.                 (SELECT categoryid FROM Production.Categories WHERE categoryname = @categoryname),
  22.                 @unitprice)
  23.     END;
  24.  
  25. EXEC dbo.ProductAdd @productname = 'Product XXXCC', @categoryname = 'Seafood', @unitprice = 123, @suppliername = 'Supplier OGLRK'
  26.  
  27. --3 zad: discount nie brałem pod uwagę--
  28.  
  29. IF EXISTS (SELECT * FROM sys.procedures WHERE name= 'deleteOrder' AND type='P')
  30.     DROP PROCEDURE [dbo].[deleteOrder]
  31. GO
  32.  
  33. CREATE PROCEDURE dbo.deleteOrder
  34.     @orderid int,
  35.     @poscount int = NULL,
  36.     @posvalue money = NULL
  37. AS
  38. set nocount on;
  39. IF NOT EXISTS (SELECT orderid FROM Sales.OrderDetails WHERE orderid = @orderid)
  40.     PRINT 'Nie istnieje zamówienia o takim id lub podany id jest równy zero'
  41. ELSE IF ((SELECT count(orderid) FROM Sales.OrderDetails WHERE orderid = @orderid) > @poscount)
  42.     PRINT 'Liczba takich zamówień jest większa od podanej liczby'
  43. ELSE IF ((SELECT SUM(qty*unitprice) FROM Sales.OrderDetails WHERE orderid = @orderid ) > @posvalue)
  44.     PRINT 'Suma zamówienia jest większa od podanej'
  45. ELSE
  46.     BEGIN
  47.     DELETE FROM Sales.OrderDetails WHERE orderid = @orderid;
  48.     PRINT 'Deleted successfully'
  49.     END
  50.  
  51. EXEC dbo.deleteOrder @orderid = 10324, @poscount = null, @posvalue = 6200
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement