How do I count the rows in SQL Statement

I have an .asp page that prints out all machines without the latest DAT (virus definintion file)
It works fine.

On this same page I need to count the rows of the following sql statement.
then print it in an aspx page

as
response.write "Total Number of Machines " & count

select EPOComputerProperties.ComputerName,
      EPOComputerProperties.IPV6,
      EPOComputerProperties.DomainName,
      EPOLeafNode.Tags,
      dbo.epofn_EPOComputer_GetOS (EPOLeafNode.AutoID) as 'OS',
      dbo.epofn_EPOComputer_GetProducts(EPOLeafNode.AutoID) as 'products',
      EPOLeafNode.LastUpdate,
      EPOProdPropsView_VIRUSCAN.productversion,
      EPOProdPropsView_VIRUSCAN.hotfix,
      EPOProdPropsView_VIRUSCAN.datver,
      EPOProdPropsView_VIRUSCAN.enginever,
      EPOLeafNode.AutoID
from EPOLeafNode left join EPOProdPropsView_VIRUSCAN on EPOLeafNode.AutoID = EPOProdPropsView_VIRUSCAN.LeafNodeID left join EPOComputerProperties on EPOLeafNode.AutoID = EPOComputerProperties.ParentID
where ( ( ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 0 ) or ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 5 ) or ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 7 ) ) and ( EPOProdPropsView_VIRUSCAN.verDAT32Major >= 5952 ) )
LVL 10
abraham808Asked:
Who is Participating?
 
dougaugConnect With a Mentor Commented:
select count(*)
from EPOLeafNode left join EPOProdPropsView_VIRUSCAN on EPOLeafNode.AutoID = EPOProdPropsView_VIRUSCAN.LeafNodeID left join EPOComputerProperties on EPOLeafNode.AutoID = EPOComputerProperties.ParentID
where ( ( ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 0 ) or ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 5 ) or ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 7 ) ) and ( EPOProdPropsView_VIRUSCAN.verDAT32Major >= 5952 ) )
0
 
abraham808Author Commented:
I tried this.

this is the error

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.
Msg 102, Level 15, State 1, Line 14
Incorrect syntax near 'EPOProdPropsView_VIRUSCAN'.

Line 1 =
select count(*) EPOComputerProperties.ComputerName,

Line 14 =
where ( (( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 0 ) or ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 5 ) or ( EPOProdPropsView_VIRUSCAN.verProductMajor = 8 and EPOProdPropsView_VIRUSCAN.verProductMinor = 7 )       ) and ( EPOProdPropsView_VIRUSCAN.verDAT32Major >= 5952 ) )

0
 
dougaugCommented:
The line 1 syntax is incorrect.

You can use one of these:

select count(*)

or

select count(EPOComputerProperties.ComputerName)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
abraham808Author Commented:
My fault.  I didn't copy your anwer the first time, anyway that worked!

Do you know how to take that result and print it to a asp page?
response.write "Total Number of Machines " & count

I'm thinking it should be a function?
0
 
dougaugCommented:
I'm not an asp specialist. I think you should execute your command in a recordset object and read it using some property like a field.

Try this:

<%
set conn = server.createobject("adodb.connection")
conn.open " "          '<--- Type your DB connection parameters here
sSQL="select count(*) from table...."  '<--- Type all your query here
set rs=conn.execute(sSQL)

response.write "Total Number of Machines " & rs.fields.item(0).value

'close recordset and connection
rs.close
conn.Close
%>
0
 
abraham808Author Commented:
the thing is i already read something else into a recordset object, what can i do to read it in a different function or sub?
0
 
dougaugConnect With a Mentor Commented:
Write something like this:

<%
Function CountMachines
  set conn = server.createobject("adodb.connection")
  conn.open " "          '<--- Type your DB connection parameters here
  sSQL="select count(*) from table...."  '<--- Type all your query here
  set rs=conn.execute(sSQL)

  CountMachines = rs.fields.item(0).value

  'close recordset and connection
  rs.close
  conn.Close

End Function

response.write "Total Number of Machines " & CountMachines
%>
0
 
abraham808Author Commented:
Thank you so Much!  The solution was complete and perfect.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.