Results 1 to 7 of 7

Thread: SQL Functions in ADO

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160

    SQL Functions in ADO

    how to have any sql function in ado ? like GETMAX() I don't want to modify my query or requery it I just want to run SQL function and put it into a variable or maybe just move cursor to that record


    thanks alot.
    S. Mohammad Najafi

  2. #2
    Lively Member twistedthoughts's Avatar
    Join Date
    Oct 2002
    Location
    dxb
    Posts
    114
    ???

  3. #3
    Hyperactive Member goatsucker's Avatar
    Join Date
    Dec 2002
    Location
    Leeds, England
    Posts
    283
    No different that if it was a normal SELECT query. It is good practice however to give your aggregate function field a name e.g.
    Code:
    SELECT MAX(field1) as maxField1
    FROM tbl1
    Then you can reference this field by name e.g.
    VB Code:
    1. dim intMax as integer
    2. intMax = rst.fields("maxField1").value
    If you do not give your field a name and cannot change your SQL query then use the field's number (e.g. in the above example as there is only one field you would use rst.fields(0).value)

    I hope this answers your question
    After all "Rust Never Sleeps"

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    I'm not sure that's quite what he wanted.... I think what he's looking for is some kind of ado function that will return the max of an already existing recordset.... w/o needing to modify the query to return it ..... there is no such built in function.... but you can build one, it's not that difficult.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Member magician's Avatar
    Join Date
    Jun 2002
    Location
    Dublin
    Posts
    48
    Originally posted by techgnome
    I'm not sure that's quite what he wanted.... I think what he's looking for is some kind of ado function that will return the max of an already existing recordset.... w/o needing to modify the query to return it ..... there is no such built in function.... but you can build one, it's not that difficult.
    debug.print myrecordset.recordcount

    ' !!! .Cursorlocation Has 2 b on client side
    ' !!! myRecordset.Cursrlocation=AdUseClient

  6. #6
    Hyperactive Member goatsucker's Avatar
    Join Date
    Dec 2002
    Location
    Leeds, England
    Posts
    283
    RecordCount will just return the number of records, not the Maximum value of a particular field
    After all "Rust Never Sleeps"

  7. #7
    Member magician's Avatar
    Join Date
    Jun 2002
    Location
    Dublin
    Posts
    48
    Originally posted by goatsucker
    RecordCount will just return the number of records, not the Maximum value of a particular field
    ... Woops, could not understand question ... ;-)

    VB Code:
    1. 'here is Ur code
    2. ' myRecordset is already opened recordset with client-side cursor
    3. ' myfield - field U R trying 2 get Max() Value
    4. ' just try something like this
    5.  
    6. myRecordset.sort = "[myField] Desc"
    7. myRecordset.moveFirst
    8. debug.print myRecordset.Fields("myField")
    9.  
    10. ' Should b Max(Value)
    11. ' so, if U'll sort by "Asc", U'll have Min(value)
    12.  
    13. myRecordset.sort = ""
    14. ' unsorted recordset, cursor position onthe _first record with Max("MyField")_
    Last edited by magician; Sep 29th, 2003 at 12:27 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width