Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:54:42+00:00 2026-06-09T22:54:42+00:00

I am nearly finished with my first assignment but the last question has me

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:54:43+00:00Added an answer on June 9, 2026 at 10:54 pm

    Take a look at using the @@ROWCOUNT function after your query. This function returns the number of rows affected by the last statement. Read more about it here.

    Using your second edit above, you could do:

    DECLARE @PName varchar(35) 
    DECLARE @CName varchar(75) 
    DECLARE @RName varchar(75)
    DECLARE @rowCount int 
    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
    
    SET @rowCount = @@ROWCOUNT
    
    PRINT @PName 
    PRINT @CName 
    PRINT @RName 
    --Use @rowCount in your report.
    

    Note that you have to obtain the row count immediately after you execute the query. This way, no matter how many rows you get, you’ll have the right number – avoiding the “cheat” scenario you mentioned.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've nearly finished my first App but i'm getting a weird EXC_BAD_ACCESS that nearly
I'm nearly finished with writing my first iOS application, but I ran into a
I have an app that is nearly finished but encountered an annoying problem. In
my app is nearly finished but a leak has appeared. After having spent an
I am nearly finished with the development of an Android application. But there seems
I just looked back through the project that nearly finished recently and found a
I have nearly finished my app but still have to make sure landscape orientations
Description: I've got a project which is nearly finished now, but I've noticed the
So, my team is using the HTML5 Boilerplate and has the site nearly finished.
I'm nearly finished with this project but I have been beating my head against

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.