Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:21:15+00:00 2026-06-15T18:21:15+00:00

I am learning how to use parameters in an excel-driven SQL query (in fact

  • 0

I am learning how to use parameters in an excel-driven SQL query (in fact I am still learning SQL in general). Thanks to the nice people that helped me build my query to modify the results as I need, I want to take this a step further and supply a parameter in Excel to filter the results.

Here is my query:

SELECT 
    fun.FUNCTION_ID
    ,COALESCE(fun.parent_function, fun2.function_id) as PARENT_FUNCTION
    ,fun.MODULE_ID
    ,fun.DESCRIPTION
    ,fun.FUNCTION_PURPOSE
    ,fun.PB_OBJECT
    ,sec.GROUP_ID
    ,sec.ACCESS_LEVEL
from 
    MODULE_FUNCTION fun

    LEFT JOIN MODULE_FUNCTION fun2
    ON fun.function_id = fun2.function_id
    AND fun2.function_id IN (SELECT parent_function FROM MODULE_FUNCTION)

    LEFT OUTER JOIN FUNCTION_SECURITY sec
    ON fun.FUNCTION_ID = sec.FUNCTION_ID
    AND sec.GROUP_ID = 'GROUP_NAME'

What I need to do is allow people from a team to run this query in the excel sheet and supply their group name for the “GROUP_NAME” in the second JOIN. Unfortunately I cannot use the syntax WHERE (sec.GROUP_ID = ?) (found here) as I need to pull all results from the MODULE_FUNCTION table and only insert results on the right from the FUNCTION_SECURITY table when there is a match on the supplied group (leaving null when there is no match).

When I try to use AND (sec.GROUP_ID = ?) at the end I get a “Invalid Parameter Number” in Excel. From what I have gathered, the “?” can only be use with WHERE (and works find for me in test queries).

I have tried many things, including declaring a @parameter, but no avail.

I’m tempted to try this technique but I’d like to avoid VB if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:21:16+00:00Added an answer on June 15, 2026 at 6:21 pm

    I know you said you want to avoid VB, but it isn’t too complicated for what you want to do.

    You can have the sheet have a cell for the group name, then a button that calls a macro where you would change the sql query to adjust for the group_id.

    Something like:

    Dim sql As String
    
    sql = "select ... from ... and sec.GROUP_ID = '?'"
    sql = Replace(sql, "?", Worksheets("Analysis").Range("A1").Value)
    
    With ActiveWorkbook.Connections("connection name").OLEDBConnection
        .CommandText = sql
        .Refresh
    End With
    

    Where:

    Worksheets("Analysis").Range("A1").Value
    

    is the Group_ID. You can set this to a specific cell in any sheet in your workbook. I would create a button right next to it called “Refresh table” or something like that.

    If you already made a table that links to a database, then there is a connection object in Excel. Go to the Data tab, then click “Connections”. A new window will pop up. Find the connection that matches to the SQL query. Click on that connection and click “Properties” then change the connection name to something easy (it’s usually some long name based on the server/table you connect to). Use that for the

    ActiveWorkbook.Connections("connection name")
    

    section.

    Link to create button on worksheet and link to macro:

    http://office.microsoft.com/en-us/excel-help/add-a-button-and-assign-a-macro-to-it-in-a-worksheet-HP010236676.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning how to use SQL and Stored Procedures. I know the syntax
Still new to python and django, though learning ;-) I have a view that
I have been learning to use prepared and bound statements for my sql queries,
I'm still learning Scala, but one thing I thought was interesting is that Scala
I am learning to use GWT with App Engine in Eclipse. I included the
I am just learning to use Services, and am sort of stuck. I have
i am learning to use SO_SNDTIMEO and SO_RCVTIMEO to check the timeout. It is
I'm just learning to use lazy sequences in Clojure, and I'm not sure what
I am learning to use Subversion and am experimenting. I checked out a copy
I'm learning to use vlad the deployer and I've got a question. Since I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.