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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dougaugCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
dougaugCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.