Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report Conditions 1

Status
Not open for further replies.

charbrad

Technical User
Nov 7, 2002
132
US
I have a report that gives total pounds produced in a day. My question is if there is a way to add a condition to my report so that if totallbs = 0 the report will not generate? This is ASP code and it is a report file being written to the page as HTML.
Below is the SQL Query used in the report
Code:
SQLQuery = "SELECT ISNULL(SUM(LaborVariance),0) LaborVariance, ISNULL(SUM(MaterialVariance),0) MaterialVariance, ISNULL(SUM(LBSProduced),0) LBSProduced, CASE WHEN ISNULL(SUM(ConsumedQTY),0) = 0 THEN 0 ELSE ISNULL(SUM(LBSProduced),0)/SUM(ConsumedQTY)*100 END Yield, COUNT(DISTINCT Item) ItemsProduced, COUNT(MO) JobsClosed FROM ReportsMOVariance (NOLOCK) WHERE CloseDate = '" & ReportDate & "'"
rs.Open SQLQuery, MyConn 
p=rs.GetRows()
rs.close
 
Are you asking if all your select columns that have SUM on them add up to 0??

I'm not sure what all fields constitute the total pounds.




[monkey][snake] <.
 
Sorry for not being clear.....I am very, very new to ASP. What I can see from the code, yes if all select columns that have SUM on them add up to 0.
 
Put that in your SQL statement. It'll look like a long mess, but it's the most efficient way and should be fast.

When messing with ASP and SQL, the best way is to try to get your SQL to do as much of the work ar it can for you.

Code:
SQLQuery = "SELECT ISNULL(SUM(LaborVariance),0) LaborVariance, ISNULL(SUM(MaterialVariance),0) MaterialVariance, ISNULL(SUM(LBSProduced),0) LBSProduced, CASE WHEN ISNULL(SUM(ConsumedQTY),0) = 0 THEN 0 ELSE ISNULL(SUM(LBSProduced),0)/SUM(ConsumedQTY)*100 END Yield, COUNT(DISTINCT Item) ItemsProduced, COUNT(MO) JobsClosed, [!]ISNULL(SUM(LaborVariance),0) +  ISNULL(SUM(MaterialVariance),0) + ISNULL(SUM(LBSProduced),0) + CASE WHEN ISNULL(SUM(ConsumedQTY),0) = 0 THEN 0 ELSE ISNULL(SUM(LBSProduced),0)/SUM(ConsumedQTY)*100 END totalPounds[/!] FROM ReportsMOVariance (NOLOCK) WHERE CloseDate = '" & ReportDate & "'"

Then open your recordset and only create a report if totalPounds > 0.
Code:
rs.Open SQLQuery, MyConn 
if (rs.RecordCount && rs("totalPounds")) then
   p=rs.GetRows()
   rs.Close
   //Build report here
else
   rs.Close
end If


[monkey][snake] <.
 
I am getting this error....

"Operation is not allowed when the object is closed
 
Somewhere in your code, you are trying to pull a value from the recordset AFTER you do an rs.Close.

I'm assuming you are pulling the data "on-the-fly" to create the report. So in that case, you won't use the statement

p = rs.GetRows()

Change your code like so
Code:
rs.Open SQLQuery, MyConn 
if (rs.RecordCount && rs("totalPounds")) then
   p=rs.GetRows()
   //Build report here
   [!]rs.Close[/!]
   put the close AFTER you build the report
else
   rs.Close
end If

This change is all based on assumption. I'm assuming you are pulling data from the recordset as you are writing the report.

After you get this worked out, you may want to check out the .GetRows() function.




[monkey][snake] <.
 
Thank you Monksnake...have a star for your brilliance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top