+ Reply to Thread
Results 1 to 7 of 7

SQL String in Excel VBA

  1. #1
    Registered User
    Join Date
    01-17-2016
    Location
    England
    MS-Off Ver
    2013
    Posts
    23

    Question SQL String in Excel VBA

    Hi,

    I am importing data from our SQL server in to Excel, it works fine:
    Please Login or Register  to view this content.
    Once it is imported to the Excel sheet I then (in VBA) concatenate the two fields org_param_value.param_effective_date and org_parameter.param_id in to the blank 'Lookup' column I have at the beginning of the SQL.

    I want to be able to do this without the extra vba to concatenate both field. I have tried: SELECT CDbl([org_param_value].[param_effective_date]) & [org_parameter].[param_id],

    this doesn't work, I get an error: SQL Syntax - ([org_param_value].[param_effective_date]) & [org_parameter].[param_id], near line 1.

    Using this in Access works.

    any help appreciated.

    thanks
    Kerry

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

    Re: SQL String in Excel VBA

    What are the data types of [org_param_value].[param_effective_date]) & [org_parameter].[param_id] and how should it look when concatenated? Could you give some examples?

  3. #3
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: SQL String in Excel VBA

    If you just want to chain them together you can do this.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-17-2016
    Location
    England
    MS-Off Ver
    2013
    Posts
    23

    Re: SQL String in Excel VBA

    Hi,
    I need the date converting to a serial number (as per Excel) and then concatenating. So Access will output the query like this:

    LookupValue param_effective_date param_id
    42498205561 08-May-16 205561
    42499205562 09-May-16 205562
    42499205563 09-May-16 205563
    42499205564 09-May-16 205564

    Need to replicate this in the sql in VBA.

    Any ideas?

    many thanks
    Kerry

  5. #5
    Registered User
    Join Date
    01-17-2016
    Location
    England
    MS-Off Ver
    2013
    Posts
    23

    Re: SQL String in Excel VBA

    Quote Originally Posted by Kyle123 View Post
    What are the data types of [org_param_value].[param_effective_date]) & [org_parameter].[param_id] and how should it look when concatenated? Could you give some examples?
    [org_param_value].[param_effective_date] is Date/Time and [org_parameter].[param_id] is a number Long Integer

  6. #6
    Registered User
    Join Date
    01-17-2016
    Location
    England
    MS-Off Ver
    2013
    Posts
    23

    Re: SQL String in Excel VBA

    Can anyone help out with this, it's driving me crazy?!

  7. #7
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: SQL String in Excel VBA

    Hi KML,
    In case you have not figured it out yet this should do the Trick
    Please Login or Register  to view this content.
    If your workbook has the 1904 option activated you need to change the Date in the SQL accordingly

    Greets Loki

+ 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. Replies: 1
    Last Post: 08-07-2015, 04:01 PM
  2. Replies: 7
    Last Post: 04-15-2015, 09:32 AM
  3. Replies: 5
    Last Post: 02-11-2015, 10:41 PM
  4. Replies: 2
    Last Post: 12-29-2014, 11:24 PM
  5. VBA Find Partial String in String Array and Output the Found String Array Value
    By scherich in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2014, 11:20 AM
  6. Replies: 3
    Last Post: 11-22-2013, 10:43 AM
  7. Replies: 1
    Last Post: 08-04-2009, 06:42 AM

Tags for this Thread

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