+ Reply to Thread
Results 1 to 30 of 30

Pull all record from a column in a SQL table

  1. #1
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Pull all record from a column in a SQL table

    I attempting to pull all record from a column in a SQL table. I'm pulling in the first record but thats it. There are 152 record in the column that I need to pull in and put in a column in excel. Below is my code. Any ideas whta I'm doing wrong.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    That's my output. The line before that is my input.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    There's nothing wrong with your input, the SQL statement is fine.

    This isn't going to return all the records.
    Please Login or Register  to view this content.
    GetRows will return all the records in an array.

    The alternative is to loop through the recordset.

  5. #5
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    Normaly my code would look something like SQLLaborOper = recS(0). which would referance item 1 and recS(1) would referance item 2. Anyway im only geting 1 item back from my statement I know that there are over 150. So I'm not sure whats wrong.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    When you use recS(0) how many records/values does it return?

    It'll be the value from the first field of the current record.

  7. #7
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    Yes GetRows works very well for putting the datat into the cells. You are one step ahead of me. My problem is getting all the data from the database. Im only getting one record back. I should be getting 150.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    ADO's GetRows doesn't put data in cells, it returns records from a recordset.

    http://msdn.microsoft.com/en-gb/libr...(v=vs.85).aspx

    If you wanted the entire recordset in cells you would use CopyFromRecordset.
    Last edited by Norie; 11-19-2012 at 04:21 PM.

  9. #9
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    I understand that. this statement is what is getting the data from the database. Correct ?
    Please Login or Register  to view this content.
    Conn is the connection and recS is the record set. If you go into VBE and expand recS while debugging you can see all the data and it atributes I only see 1 record not the 150 that I need. so at this point
    Please Login or Register  to view this content.
    isnt my problem since I do not have all the data from the database.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    When you expand recS you will not see all the data, you'll see properties of the recordset.

    One of these properties is the Fields collection which holds the data.

    The data in the Fields collection when you first open the recordset will be for the first record.
    Last edited by Norie; 11-19-2012 at 04:37 PM.

  11. #11
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    So your saying all the data is there and I'm just not seeing it?

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    I didn't say that.

    To get all the data you can use various methods GetRows being one of them, but you can also loop through each record or use CopyFromRecordset to put the data on a worksheet.

    What is it exactly you are trying to do?

    Where are you using this function?

  13. #13
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    the function is being used on another sheet and will be refernaced in a dropdown. based on the selection from the dropdown some calculations are made.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    Do you mean this is the used to populate the dropdown?

  15. #15
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    THat is correct.

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    Can you post the code that is using the function to populate the dropdown?

    PS Have you tried GetRows yet?

  17. #17
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    No code its just an excel dropdown. I tried it when you first posted and all I got whs the first record. Sorry about this I'm not trying to be a pain. I just am one

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    How exactly did you check the no of records that were returned?

    Also, how can you use this function on it's own to populate a drodown?

  19. #19
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    dropdowns utilise a rage of cells that are populated. As long as they are populated a dropdown wont care how. There was a record returned. The first one thats it there should have been 150 there was only 1.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    How are you putting values in the cells?

    Like I said a few posts ago you should use CopyFromRecordset.
    Please Login or Register  to view this content.
    GetRows put's the records in an array, you can't transfer that directly to cells without some work.

  21. #21
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    The dropdown is created by going to Data > Data Validation > and selecting List.

  22. #22
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    That did not work.

  23. #23
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    What did not work, how did it not work and what exactly did you try?

  24. #24
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    OK I figured out what the problem was its
    Please Login or Register  to view this content.
    this looks at rows I need columns. Any one know what ADODB looks at columns?

  25. #25
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    That's not right.

    A table in a database is made up of records and fields which can be equated to rows and columns.

    With your query you are returning the value of one column (field) for all the rows (records) from the table.

  26. #26
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    OK I must be tired. I'm giving up for the day.

  27. #27
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    I found the code I needed to make it work thanks for all the help
    Please Login or Register  to view this content.

  28. #28
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    Just like I suggested back at the start - loop through the recordset.

    Anyway you've got it working and that's the important thing.

  29. #29
    Forum Contributor
    Join Date
    09-21-2012
    Location
    illinois
    MS-Off Ver
    Excel 2010
    Posts
    242

    Re: Pull all record from a column in a SQL table

    I just didnt know how to go about it. Thanks for the help.

  30. #30
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pull all record from a column in a SQL table

    Sorry, I could have sworn I posted a small example, but I checked and I can't see it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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