+ Reply to Thread
Results 1 to 8 of 8

SQL & passing in ONE parameter (without using pivot table)

  1. #1
    Registered User
    Join Date
    10-10-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    6

    SQL & passing in ONE parameter (without using pivot table)

    So I have:

    Excel 15.
    An excel sheet, linked to a Postgres DB
    I am pulling data successfully into the XLS, via ODBC

    Objective

    Pass in ONE parameter (UserName) and use that in the query

    The way I use the queries is
    - Data -> New DB Query
    - in MS Query, paste in my SQL (which works)

    Next is the Import Data screen, which lets me put the data into the sheet
    That all works.

    How do I pass in a parameter?
    In MS Support "Customize a parameter query"

    The article indicates a parameter can be passed in, but I dont understand how.

    Ideally, I like to have a cell with my input parameter to be used in the SQL
    (I can pick that up via VBA if needed. My VBA is decent)


    Thanks

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: SQL & passing in ONE parameter (without using pivot table)

    Hi,
    You need to edit the SQL to add ? as the parameter. That will then enable the Parameters option for the query and you can link it to a cell.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    10-10-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    6

    Re: SQL & passing in ONE parameter (without using pivot table)

    Quote Originally Posted by xlnitwit View Post
    Hi,
    You need to edit the SQL to add ? as the parameter. That will then enable the Parameters option for the query and you can link it to a cell.
    Do you have an example?

    thanks

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: SQL & passing in ONE parameter (without using pivot table)

    What is your SQL? Please highlight the part that should use the parameter.

  5. #5
    Registered User
    Join Date
    10-10-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    6

    Re: SQL & passing in ONE parameter (without using pivot table)

    OK - a simplified version, where I want to pass in DATE

    SELECT
    u."createdAt" AT TIME ZONE 'America/Toronto' AS "Sign Up Date",
    U.first_name as "First",
    U.last_name as "Last",

    from users U

    WHERE (U."createdAt" AT TIME ZONE 'America/Toronto')>= DATE



    Thanks for the help

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: SQL & passing in ONE parameter (without using pivot table)

    Your WHERE clause would become
    WHERE (U."createdAt" AT TIME ZONE 'America/Toronto')>= ?

  7. #7
    Registered User
    Join Date
    10-10-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    6

    Re: SQL & passing in ONE parameter (without using pivot table)

    So I did that exactly. passed in a number using the pop up parameters box
    and got the following error

    Days Back.png

    Guessing here that its passing in a String rather than an integer.
    Not sure how to specify that.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: SQL & passing in ONE parameter (without using pivot table)

    20 is not a date value.

+ 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. passing Parameter values to table in a different sheet using VBA in Excel
    By nockvba in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2014, 10:55 AM
  2. Passing subroutine as a parameter
    By jartzh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-26-2009, 03:39 PM
  3. passing column as parameter
    By jartzh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-20-2009, 12:10 PM
  4. Passing Parameter between Excel and asp
    By jsy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2006, 04:43 AM
  5. Parameter for SQL query to pivot table
    By MaxBrit in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-25-2006, 04:38 AM
  6. Passing a Sub's name as parameter
    By Stefi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-20-2005, 04:05 PM
  7. [SOLVED] Pivot Table From Access Parameter Query
    By Paul Smith in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2005, 12:06 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