+ Reply to Thread
Results 1 to 4 of 4

ADO link to MySQL - Strange Results?!

  1. #1
    Registered User
    Join Date
    10-01-2008
    Location
    UK
    Posts
    3

    ADO link to MySQL - Strange Results?!

    I want to be able to run queries ona MySQL database from Excel. It is something I have never done before so I set up a prototype model just to see if I could set up the link. The following code works except that only the ID's are returned, not the 'description'. Oddly, the same query works fine when looking at the same table in a MS SQL database (and MS Access).

    Any idea's why? (the UNION seems to be casing the problem as without the UNION all data is returned).

    Thanks in advance.


    Sub RecordsetwithMYSQL()

    'Open Connection and Recordeset
    Dim rs As ADODB.Recordset
    Dim SQLString As String
    Set rs = CreateObject("ADODB.Recordset")

    ' Define SQL String
    SQLString = "SELECT ID, Description from evo_CustomerType WHERE ID <= 10 " & _
    "UNION SELECT ID, Description from evo_CustomerType WHERE ID > 30"


    'Set Recordset Properties
    With rs
    .Source = SQLString
    .ActiveConnection = "Warehouse-mysql" 'DatabaseName (in ODBC DSN)
    .Open
    End With

    'Return Data to Excel
    Sheet1.Range("a1").CopyFromRecordset rs

    'Close Recordset
    rs.Close
    Set rs = Nothing

    End Sub

  2. #2
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808
    UNION ALL is only really used to extract data from 2 tables where the column headings are exactly the same mate.

    so really the only reason you would use it is if you had 2 table say containing data from domain 1 and domain 2 respectively.

    i.e.

    Please Login or Register  to view this content.
    Hope that helps a little mate
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  3. #3
    Registered User
    Join Date
    10-01-2008
    Location
    UK
    Posts
    3
    Thanks MacDave. The query is a simple prototype just to test that I can link into a MYSQL database and that I can return data. Ultimately, I would want to add multiple tables, joins, Unions, subqueries etc but for now am trying to keep the SQL as simple as possible.

    Its the fact that the UNION is not returning anything in the 'Description' fields that is confusing me, especially considering that this works fine for MS SQL databases.

  4. #4
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Hey

    Yeah good luck with that mate lol i use SQL here and there and it's an pain in the butt, even more so when your throwing in excel because of god damn speech marks etc.

    anyway like you said it works ok without it so "if it ain broke...."

    cheers

+ 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. Strange Behavior when I link to a File
    By ions in forum Excel General
    Replies: 7
    Last Post: 10-17-2007, 02:52 AM
  2. Stopping a spinner when it's reached end of results
    By happyfingers in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2007, 01:27 PM
  3. VLOOKUP - Strange results
    By paulwelburn in forum Excel General
    Replies: 6
    Last Post: 05-31-2007, 05:41 PM
  4. Insert Link In Email
    By JoJo in forum Excel General
    Replies: 0
    Last Post: 04-06-2007, 09:36 AM
  5. Link In Email
    By JoJo in forum Excel General
    Replies: 1
    Last Post: 04-05-2007, 07:17 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