+ Reply to Thread
Results 1 to 12 of 12

Transfer recordset to variable (SQL)

  1. #1
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Transfer recordset to variable (SQL)

    hi,

    i'm trying to copy a recordset into a variable. i can copy it to an excel cell with the
    Please Login or Register  to view this content.
    command, but as soon as i try to copy the value to a variable using:
    Please Login or Register  to view this content.
    it returns a null value...
    i need to perform some calculations using another value i've grabbed from a table so what would be the best way to get my value into a variable?

    the value returned is a single digit btw

    thanks

    Jonathan
    Last edited by Jollyfrog; 10-21-2010 at 09:07 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Transfer recordset to variable (SQL)

    [removed - nonsense I'm afraid...]
    Last edited by DonkeyOte; 10-21-2010 at 07:13 AM.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Transfer recordset to variable (SQL)

    Jonathan, earlier post was nonsense, apologies!

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 10-21-2010 at 07:16 AM. Reason: removed note re: Transpose as it's always relevant

  4. #4
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Transfer recordset to variable (SQL)

    hmm i've tried this and it seems to think the EOF is true.. i copy the recordset into a cell just to see whats going on... and that returns the correct value, 27...

    vtemp doesn't return any value as nothing is parsed into it

    thanks

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transfer recordset to variable (SQL)

    rst already is a variable, so I don't really see what it is you want to do?
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Transfer recordset to variable (SQL)

    i wan't to perform an arithmetic operation on it.

    Please Login or Register  to view this content.
    like that only a bit more complicated...

    currently code like that returns type mismatch error

  7. #7
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Transfer recordset to variable (SQL)

    To clarify what i want to do:

    Please Login or Register  to view this content.
    i'm ok with getting balues from tables (thanks to some help )
    however recording values returned from the tables is presenting a difficulty.

    thanks


    Jonathan

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transfer recordset to variable (SQL)

    Wouldn't it be easier to do all that in the query (or queries)?
    You can't simply multiply a recordset by 5 as a recordset can contain many records and many fields per record. If you only have one field and one record, then you need to refer to that field specifically:
    Please Login or Register  to view this content.
    for example.

  9. #9
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Transfer recordset to variable (SQL)

    i wanted to parse the record to a variable (integer) so i could then perform mathematical operations upon it. I also need to use the result of a query to form the paremeters for the next query, i thought the best was to do this would be to use a variable set from a recordset.

    I'm not really sure how to the whole process as a single query, i assumed combining 3 separate queries was better.

    however

    when i use the code

    Please Login or Register  to view this content.
    range g5 returns the correct value (27)

    but temp does not accept a value

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transfer recordset to variable (SQL)

    Put the temp line before the CopyFromRecordset line.

  11. #11
    Registered User
    Join Date
    09-23-2010
    Location
    London, England
    MS-Off Ver
    2007
    Posts
    97

    Re: Transfer recordset to variable (SQL)

    wait whaat!.. that works hmm.. well thankyou very much :-)


    does copyfromrecordset delete the record then?

    thanks again

  12. #12
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transfer recordset to variable (SQL)

    No, it doesn't delete it, but it does move to the end of the recordset, so there is no current record for you to read.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1