Consulting

Results 1 to 5 of 5

Thread: SELECT INTO via OpenRowset

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    SELECT INTO via OpenRowset

    I have an issue where updating from Access to SQL Server might involve duplicate rows on a non-primary key field.

    Currently This is performed by an ADO While loop which iterates the Access Table by row. I have tried using an ADO Command with [pseudo-code] OpenRowset

    [vba]
    SELECT * INTO dbo.SQLTable
    FROM OPENDATASOURCE( 'Microsoft.Jet.OLEDB.4.0',
    'Data Source = ''C:\Access.mdb'',"SELECT * FROM AccessTable WHERE NOT EXIST ("SELECT * FROM dbo.SQLTable WHERE dbo.SQLTable.Field = AccessTable.Field"))

    [/vba]

    But nothing happens. I assume there is improper syntax, and if it catches anyones eye, I would appreciate any corrections. Thanks... Stan

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    my bad the title was openrowset and I used opendatasource in the code. However, I don't believe there is that much difference between the two, and neither works.

  3. #3
    VBAX Mentor tpoynton's Avatar
    Joined
    Feb 2005
    Location
    Clinton, MA
    Posts
    399
    Location
    I ventured into here to learn, so excuse my incorrectly pointing this out of it is wrong!

    does there need to be a closing single quote between the two closing parentheses? (closes quote at 'data source...)

  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Stan,

    I think I saw ' ' in the connection string I'm pretty sure it is a typo here.

    but .....
    [VBA]"'SELECT * INTO dbo.SQLTable FROM OPENDATASOURCE" & _
    "( 'Microsoft.Jet.OLEDB.4.0', 'Data Source = C:\Access.mdb'," & _
    "'SELECT * FROM AccessTable WHERE NOT EXIST (SELECT * FROM dbo.SQLTable WHERE dbo.SQLTable.Field = AccessTable.Field)')'"[/VBA]

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Tommy
    Stan,

    I think I saw ' ' in the connection string I'm pretty sure it is a typo here.
    I think each parameter has to be enclosed in single/double quotes, for example


    [vba]
    SELECT c.*, o.*
    FROM Northwind.dbo.Customers AS c INNER JOIN
    OPENROWSET('Microsoft.Jet.OLEDB.4.0',
    'c:\MSOffice\Access\Samples\northwind.mdb';'admin';'mypwd', Orders)
    AS o
    ON c.CustomerID = o.CustomerID
    [/vba]

    otherwise I would get a syntax error. I have another realtime test for OpenRowset(), and perhaps this thread can be re-visited.

    Stan

Posting Permissions

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