Query for a report
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Query for a report

  1. #1
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Query for a report

    I'm trying to create a query for a report but I don't seem to come with the right query for it, I'm kinda new at doing queries and reports, anyway here's what I have.

    I have two tables that looks like this:

    t1
    -------------
    | id | date|
    | 1 | ..... |
    | 2 | ..... |
    | 3 | ..... |
    | 4 | ..... |
    -------------

    t2
    ------------------------
    | id | field1| field2 |
    | 1 | ..... | ....... |
    | 2 | ..... | ....... |
    | 3 | ..... | ....... |
    | 4 | ..... | ....... |
    ------------------------

    i want to be able to select all fields from t2 based on a date from table 1 there are both linked with by the id, it's supposed to looks like this:
    --------------------------------
    | id | date | field1 | field2 |
    | 1 | ..... | ....... | ....... |
    | 2 | ..... | ....... | ....... |
    | 3 | ..... | ....... | ....... |
    | 4 | ..... | ....... | ....... |
    --------------------------------

    I think i need to use the inner join but i haven't been able to get the right syntax so if you could point me to the right direction i would really appreciate it

    and also how can i add the results of all the rows so that it only displays 1 row, what I'm trying to do is add the totals in each field field1, field2 and then display those results on a bar graph, I'm I taking the right approach for this problem? or maybe this last step can be done by the reports software instead of the query? I'm using CR 2008

    thanks guys.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,608

    Re: Query for a report

    Didn't you ever hear about JOIN?
    Code:
    SELECT t1.id, t1.date, t2.field1, t2.field2
    FROM t1 INNER JOIN t2 ON t1.id = t2.id
    Victor Nijegorodov

  3. #3
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Re: Query for a report

    Quote Originally Posted by VictorN View Post
    Didn't you ever hear about JOIN?
    yeah i've heard about it but im just not that familiar with sql syntax I've been doing a bunch of googleing but this got me on the right track, thanks

  4. #4
    Join Date
    Dec 2009
    Posts
    596

    Re: Query for a report

    If you ever need help with joins; something that you can do is build the query with Query Design in Microsoft Access and view the SQL in SQL view. If you aren't familiar with that, it's a really easy way of doing queries that won't take much time to learn how to use. Then you will be able to see how it's done and won't depend on it or the peanut gallery.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center