+ Reply to Thread
Results 1 to 9 of 9

Subqueries - multiple connection strings

  1. #1
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Subqueries - multiple connection strings

    Hi, main query (database 1) would have an inner part with a subquery (database 2).
    Is it possible to run this in 1 sequence and spit out one result set into new Listobject,
    alternatively Recordset?
    Do you have such example please ?
    Last edited by pulsar777; 08-09-2016 at 08:19 AM.

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Subqueries - multiple connection strings

    Not able to understand properly.. Could you please clarify a bit?
    Cheers!
    Deep Dave

  3. #3
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: Subqueries - multiple connection strings

    A simple concept would look like this:

    Please Login or Register  to view this content.
    So idea is to create new ListObject table where external source would present the SQL which has 2 connections .
    Last edited by pulsar777; 08-10-2016 at 01:17 PM.

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Subqueries - multiple connection strings

    Is the Sub Query to a different Server or a different Database?

    Besides, (Though never tried it before) If such a query executes properly on SQL, if should work without any problems in Excel too.

  5. #5
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: Subqueries - multiple connection strings

    They're 2 different servers. A Company's software can execute that where (visually) it first connects into once source (asks for credentials), makes a pull and then asks to log into next source to complete the retrieval.
    As a user, I don't see the details of that procedure. I assume in terms of excel VBA, one Sub would establish a connection to subquery, retrieve results into a memory (Recordset) and that would be used as a parameter,
    to join with tables in main query. But from lack of my VBA-SQL knowledge, I seem not to put it into practice. Or is there a simpler way ?
    Last edited by pulsar777; 08-10-2016 at 03:13 PM.

  6. #6
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: Subqueries - multiple connection strings

    I just tried to JOIN a Recordset (subquery) with a table in main query, but I get Type Mismatch as Recordset.Source of main query expects SQL as a string.
    That part was like:

    Please Login or Register  to view this content.
    Last edited by pulsar777; 08-11-2016 at 08:41 AM.

  7. #7
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Subqueries - multiple connection strings

    You might have to Initialise 2 connections 1 after another, 1 will have the values stored in the recordset, then the connection string will initialise the 2nd connection and use the recordset values in the 2nd query.

    I will try to generate some code and post it in a while

  8. #8
    Registered User
    Join Date
    05-30-2015
    Location
    SVK
    MS-Off Ver
    2016
    Posts
    38

    Re: Subqueries - multiple connection strings

    Hi NeedForExcel,

    I established 2 connections, got the first Recordset from the subquery. That Recordset now should behave like a second table I'd like to JOIN with tables in main query. Can't figure out how to reference that rs in SQL string though. So I removed JOIN keyword and just did instead:

    Please Login or Register  to view this content.
    No error this time, but I got very strange result set

  9. #9
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Subqueries - multiple connection strings

    That Recordset now should behave like a second table
    Well, I don't think that is possible. I mean you might not be able to "Join" a SQL Table with a RS.

    Considering my limited knowledge with SQL, I might be wrong on the above statement though.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Moved to commercial services forum.
    By Midnight-Oil in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-28-2015, 01:05 PM
  2. Deleted
    By la_chua29 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-18-2015, 12:55 PM
  3. Excel 2007 : Update Connection strings in workbooks
    By Little Deuce in forum Excel General
    Replies: 3
    Last Post: 01-06-2014, 01:23 AM
  4. Editing Connection Strings and refreshing Pivot Tables
    By fadydaddy in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 06-03-2012, 04:29 PM
  5. Need to update multiple ODBC connection strings HELP!!!
    By k9-961 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2011, 01:48 PM
  6. Connection Strings
    By split_atom18 in forum Access Tables & Databases
    Replies: 5
    Last Post: 05-19-2010, 05:21 PM

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