Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    2

    Unanswered: Pass parameters to a query using a subquery

    Hi:

    I have a problem...
    I don't know how to pass parameters required (dates) to a query1, if I'm using a subquery (query2) which is using the results of query1, but I'm not showing that field on that subquery (query2)

    Example

    table1
    id - autonumeric
    id_user - id from user
    dates - date of register

    table2
    id - user id
    name - user name


    query1
    SELECT Table1.id_user, Count(Table1.id_user) AS CuentaDeid_user
    FROM Table1
    WHERE (((Table1.datess) Between [begining] And [ending]))
    GROUP BY Table1.id_user
    ORDER BY Table1.id_user;



    subquery (query2)
    SELECT query1.id_user, query1.CuentaDeid_user, Table2.name
    FROM query1 LEFT JOIN Table2 ON query1.id_user = Table2.id;

    This is just an example, the think is that I want to know that if it's possible to pass the parameters requested in query1 from the SQL of the subquery (query2)?

    Thanks a lot

  2. #2
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    I don't see any parameters in query1. A parameter would be something like:

    Declare @parameter varchar(10)
    or
    Create procedure myproc(@parameter1 varchar(10))

    Quote Originally Posted by rbecerril View Post
    Hi:

    I have a problem...
    I don't know how to pass parameters required (dates) to a query1, if I'm using a subquery (query2) which is using the results of query1, but I'm not showing that field on that subquery (query2)

    Example

    table1
    id - autonumeric
    id_user - id from user
    dates - date of register

    table2
    id - user id
    name - user name


    query1
    SELECT Table1.id_user, Count(Table1.id_user) AS CuentaDeid_user
    FROM Table1
    WHERE (((Table1.datess) Between [begining] And [ending]))
    GROUP BY Table1.id_user
    ORDER BY Table1.id_user;



    subquery (query2)
    SELECT query1.id_user, query1.CuentaDeid_user, Table2.name
    FROM query1 LEFT JOIN Table2 ON query1.id_user = Table2.id;

    This is just an example, the think is that I want to know that if it's possible to pass the parameters requested in query1 from the SQL of the subquery (query2)?

    Thanks a lot

  3. #3
    Join Date
    Apr 2012
    Posts
    2
    Thanks for your fast response.

    Maybe I'm not explaining as it has to be

    I'm using microsoft access, and i'm using visual studio to send from a web page an SQL to the database (query2) to get information from query1, but in query1 I have to introduce the dates I need this report, so when I ran this query2 in access there's an input box requesting the dates, but as I'm sending just the SQL from an external application from access I need to know how can I write the SQL for query2 in order to introduce in it the dates access will be requesting'

    Is it a little bit more simple this explanation or it was more confusing?

    Sorry I'm really new in all this

    Thanks in advance again
    Ricardo

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Ricky,

    Sorry.

    It doesn't work like that.

    It would work that if you Link the SQL Server Tables to Access

    Otherwise you need to create a stored procedure and call that whilst passing in the parameters.

    Or, you can create code in VBA, generate the query, then create a pass thru query to SQL server. In that you can pass in the dates
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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