+ Reply to Thread
Results 1 to 3 of 3

SQL Query and parameters

  1. #1
    Registered User
    Join Date
    01-29-2015
    Location
    Dallas, TX
    MS-Off Ver
    2010
    Posts
    2

    SQL Query and parameters

    My question is related to populating my SQL query values from Excel/VBA. In my query I have two types of inputs, one for a date, another for a city or list of cities. The date is working just fine and is populated in Excel as 'YYYY-MM-DD. I can do the same with a single city as 'MIAMI. What I can't figure out is how I properly populate multiple cities. The SQL which works fine in SQL Assistant would normally just read as ...in('MIAMI','CHICAGO') but from Excel I've tried all combinations of single quotes before and after, with/without comma separation, no quotes, no commas, etc. Any idea what the Excel format should be for this?

    ...

    and ca.enddate>=CAST(? AS DATE)

    and ta.targetingvalue in (?)

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: SQL Query and parameters

    If Im reading the question right then the format should be exactly the same, SQL is SQL, you construct your queries to match how they would be used in say, Access.

    Are you saying that you're having problems constructing the SQL string in VBA when there are multiple cities involved? If so, can you post more info (ideally the workbook) such as an example of the SQL you want to form and how the data for the parameters is held?
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    01-29-2015
    Location
    Dallas, TX
    MS-Off Ver
    2010
    Posts
    2

    Re: SQL Query and parameters

    I am trying to do this two different ways. I have either one cell with MIAMI, CHICAGO, DALLAS and in sql I have a ? to trigger a parameter to look at that cell. Or I have one city in one cell and another city in the next cell etc. Then in my SQL I have a ? to look at that parameter. It pulls in the one value ok, such as Miami, but if I have all three cities in the one cell it comes up with an error [Teradata][ODBC Driver] Character string truncated. Then if I try to set the parameter up to multiple cells, in my excel, it says a parameter can only be one cell.

    Trying to figure out how I can get those cities into my Sql to run the query correctly to pull back the numbers for those cities.

+ 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. Web Query with parameters (or LDAP)
    By faun in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2013, 12:47 PM
  2. MS Query - Parameters
    By mattydalton in forum Excel General
    Replies: 4
    Last Post: 11-17-2009, 11:48 AM
  3. Web Query w/parameters
    By sarnone in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-23-2009, 02:01 PM
  4. Query parameters
    By Lac in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2006, 08:10 AM
  5. query with changing parameters ...
    By kellie jones in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2006, 03:35 PM
  6. Query Parameters
    By Texas_Toast in forum Excel General
    Replies: 0
    Last Post: 01-11-2006, 11:20 AM
  7. Help with getting MS Query Parameters from a combo box....
    By kimcheebowl in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-24-2005, 12:36 PM
  8. Parameters for Query
    By Sujith in forum Excel General
    Replies: 1
    Last Post: 04-03-2005, 05:07 AM

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