Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create procedure zad8
- @prod varchar(100),
- @klient varchar(100)
- AS
- declare @klientid int(10);
- declare @produktid int(10);
- select @klientid = CustomerID from Customers where CustomerName = @klient;
- select @produktid = p.ProductID from Products p where p.ProductName = @prod;
- IF(SELECT COUNT(o.OrderID) from Orders o where o.OrderID = @klientid)
- declare @zamowienieid int(10);
- select @zamowienieid = "zamid" from
- (select top 1 od.OrderID as "zamid", SUM(od.Quantity) from OrderDetails od group by od.OrderID order by 2 ASC);
- INSERT INTO OrderDetails VALUES (@zamowienieid, @produktid, 1);
- ELSE
- select @pracownikid = "pracid" from
- (select top 1 EmployeeID, Count(OredrID) from Orders group by EmployeeID order by 2 ASC);
- INSERT INTO Orders VALUES (@klientid,@pracownikid,convert(date, getdate()),1);
- declare @orderid int(10);
- select @orderid = OrderID from Orders where CustomerID = @klientid;
- insert into OrderDetails VALUES (@orderid, @produktid, 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement