Counting unique records in a field in VBScript?

Results 1 to 3 of 3

Thread: Counting unique records in a field in VBScript?

  1. #1
    Join Date
    Dec 1969

    Default Counting unique records in a field in VBScript?

    Hi all. I am creating an ASP page that needs to count the number of unique, non-null values in a particular field. <BR><BR>I am trying the following...<BR><BR>BannerPoints = SELECT COUNT("OMC_YN") FROM BANNERSTUB<BR><BR>I&#039;m not sure if this command is only for VisualBasic and not VBScript. I tried it because I&#039;m not sure how to do this VBScript, but the browser gave me an error on the Select command, so I&#039;m assuming this is the wrong command.<BR><BR>Any thoughts would be appreciated <BR><BR>Tim <BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default SQL, not VB

    The select statement is *SQL*, not Visual Basic or VBScript or anything else. You need quotes:<BR><BR>BannerPoints = "SELECT COUNT(OMC_YN) FROM BANNERSTUB"<BR><BR>Notice that I removed the quotes around OMC_YN (I assume that&#039;s a column name). That SQL statement is valid, but to do what you want, try:<BR><BR>"SELECT COUNT(DISTINCT OMC_YN) FROM BANNERSTUB"<BR><BR>I know this works in Oracle, but I don&#039;t know about other databases.<BR><BR>HTH,<BR>G

  3. #3
    Join Date
    Dec 1969

    Default Very Simple - 1 sql statement - oRS.CursorLocatio

    Use the CursorLoction, from your select you will get a count<BR>by using the oRS.recordcount<BR><BR><BR> set oRS=Server.CreateObject("ADODB.recordset")<BR> oRS.CursorLocation= 3 <BR> sql= "Select * From rcHeadertb where substring(rcCNO,1,1)=&#039;" request("plantid") & "&#039;"<BR> oRS.Open sql, oConn <BR> <BR> response.write "Records Selected: " & oRS.RecordCount

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts