+ Reply to Thread
Results 1 to 6 of 6

Macro query against a SqlServer database

  1. #1
    Registered User
    Join Date
    03-21-2012
    Location
    Tuscaloosa, Al
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro query against a SqlServer database

    I have an existing query that is run against a sqlserver database that returns production data for a group of machines. I need another query to find the timestamp of the latest record that each machine produced. How can I do that with msquery and not have to pull in multiple days of data and use excel functions?
    Thanks

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Macro query against a SqlServer database

    Your query would look something like this:
    Please Login or Register  to view this content.
    Here is a quick explanation

    http://www.w3schools.com/sql/sql_groupby.asp
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-21-2012
    Location
    Tuscaloosa, Al
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro query against a SqlServer database

    Alan

    Thanks for the help...........but I can't seem to get the syntax correct. Here is the vba for my existing query:

    Please Login or Register  to view this content.
    Then my latest effort at your code:

    Please Login or Register  to view this content.
    I get a sql syntax error.

    Ron
    Last edited by JosephP; 10-29-2012 at 09:10 AM. Reason: code tags and remove quote

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Macro query against a SqlServer database

    Try executing the query against the database before trying to make it work with Excel, at least then you'll know the syntax is right

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro query against a SqlServer database

    shouldn't it be 'group by' instead of 'group on'?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Macro query against a SqlServer database

    JosephP, thanks. You are correct. My Bad. Tough getting old and having moments like that.

    Marizar, Kyle makes an excellent point. Make sure it works in the db first.

    Alan

+ 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