I am nearly finished with my first assignment but the last question has me stumped.
It asks:
Produce a faulty product report that displays the product returned on the 11/07/2010 due to Damaged Exterior
The expected output for this is:
FAULTY PRODUCT REPORT
--------------------------------------
Product Name: Desk
Customer Name: Simon, Kernel
Reason: Damaged Exterior
(1 rows(s) affected)
---END OF REPORT---
I found out about SQL PRINT now I seem to nearly have it all down to a T:
DECLARE @ProductName varchar(30)
SET @ProductName =(SELECT MIN(Products.ProductName) FROM Products)
DECLARE @CustomerName varchar(75)
SET @CustomerName =(SELECT MIN(Customers.FirstName+', '+Customers.Surname)
FROM Customers,CustomerReturns,Products
WHERE CustomerReturns.ReturnDate='2012/07/11'
AND Products.ProductID=CustomerReturns.ProductID
AND Customers.CustomerID=CustomerReturns.CustomerID)
DECLARE @Reason varchar(30)
SET @Reason =(SELECT MIN(CustomerReturns.Reason)
FROM CustomerReturns,Products,Customers
WHERE CustomerReturns.Reason='Damaged Exterior')
PRINT 'FAULTY PRODUCT REPORT';
PRINT '';
PRINT '---------------------';
PRINT 'Product Name: '+@ProductName;
PRINT 'Customer Name: '+@CustomerName;
PRINT 'Reason: '+@Reason;
PRINT '';
PRINT '---END OF REPORT---';
And my output:
FAULTY PRODUCT REPORT
--------------------------------------
Product Name: Desk
Customer Name: Simon, Kernel
Reason: Damaged Exterior
---END OF REPORT---
As you can see I am still missing the:
(1 rows(s) affected)
How would i make this appear without ofcourse cheating and just printing it? (because then it will stay thay way no matter how many results get returned)
EDIT:
I found doing this: SELECT @ProductName... produces the 1row(s) affected, is this correct?:
PRINT 'FAULTY PRODUCT REPORT';
PRINT '';
PRINT '---------------------';
PRINT 'Product Name: '+@ProductName;
PRINT 'Customer Name: '+@CustomerName;
PRINT 'Reason: '+@Reason;
SELECT @ProductName,@CustomerName,@Reason
PRINT '';
PRINT '---END OF REPORT---';
EIDT2:
Changed it to this:
DECLARE @PName varchar(35)
DECLARE @CName varchar(75)
DECLARE @RName varchar(75)
SELECT @PName=Products.ProductName,
@CName=Customers.FirstName+', '+Customers.Surname ,
@RName=CustomerReturns.Reason
FROM Products,Customers,CustomerReturns
WHERE CustomerReturns.ReturnDate='2012/09/28'
AND CustomerReturns.Reason='Damaged Exterior'
AND Products.ProductID=CustomerReturns.ProductID
AND Customers.CustomerID=CustomerReturns.CustomerID
PRINT @PName
PRINT @CName
PRINT @RName
but still not affected rows thingy
Any help is appreciated thank you