Results 1 to 4 of 4
  1. #1
    FoolzRailer is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    51

    Adding two colums from separate query, into a new query

    Hello

    I washoping you could help me a bit. I need to make a query, that selects certaincolumns from different tables, according to a given criteria. I got thatworking, but in the query I also need to add two columns from two differentcalculation queries.
    Depth calculation Downstream [Query 1]:
    Code:
    SELECT[Daeksel]![Daekselkote]-[Knude]![Bundkote] AS Nedstrømsdybde
    Code:
    FROMTVInspektion INNER JOIN (Knude INNER JOIN Daeksel ON Knude.ID =Daeksel.KnudeID) ON TVInspektion.Slutpunktnr = Knude.Knudenavn;
    Depth calculation Upstream [Query 2]:
    Code:
    SELECT[Daeksel]![Daekselkote]-[Knude]![Bundkote] AS Opstrømsdybde
    Code:
    FROMTVInspektion INNER JOIN (Knude INNER JOIN Daeksel ON Knude.ID =Daeksel.KnudeID) ON TVInspektion.Startpunktnr = Knude.Knudenavn;
    Those two needs to be shown as columns when I do my query based on a given criteria.
    Query with criteria [Query 3]


    Code:
    SELECTLedning.OpstroemKnudeID, Knude.Knudenavn, Ledning.NedstroemKnudeID,Knude_1.Knudenavn, Delledning.Laengde, Delledning.Handelsmaal,K_LedningMateriale.Beskrivelse, TVObs.TVObsKode, TVObs.TVObsKlasse,TVObs.Type1, TVObs.Type2
    Code:
    FROM(((((TVObs INNER JOIN (TVInspektion INNER JOIN LednHaendelse ON TVInspektion.RapportID= LednHaendelse.RapportID) ON TVObs.LednHaendelseID = LednHaendelse.ID) INNERJOIN Knude ON TVInspektion.Startpunktnr = Knude.Knudenavn) INNER JOIN LedningON Knude.ID = Ledning.OpstroemKnudeID) INNER JOIN Delledning ON Ledning.ID =Delledning.LedningID) INNER JOIN K_LedningMateriale ON Delledning.MaterialeKode= K_LedningMateriale.Kode) INNER JOIN Knude AS Knude_1 ON(Ledning.NedstroemKnudeID = Knude_1.ID) AND (TVInspektion.Slutpunktnr =Knude_1.Knudenavn)
    WHERE(((TVObs.TVObsKode)="PB") AND ((TVObs.TVObsKlasse)>=2));
    Sobasically what I’m saying is, I need the answers found in Query1 and Query 2,inserted into Query 3 (as shown on the picture), but they need to remain as separate queries.

    Click image for larger version. 

Name:	QueryDesign.jpg 
Views:	10 
Size:	101.5 KB 
ID:	24122

    I'm not sure how to best achieve this, so any help would be much appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Just put the calc in an empty column.
    you may have to put the table before the field to help...

    table1.field * tbl22.field44 /2

  3. #3
    FoolzRailer is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    51
    Quote Originally Posted by ranman256 View Post
    Just put the calc in an empty column.
    you may have to put the table before the field to help...

    table1.field * tbl22.field44 /2
    Thank you for the reply, I got that working now

    Now I have a different problem.

    I have a lot of separate queries, which are basically the same, but with different criterias (someone prefers to keep them separate). They have the same number of columns, and the columns have the same ID. I need to merge all these into one, using a Union query. How is this best achieved?

    Code:
    SELECT Ledning.OpstroemKnudeID, Knude.Knudenavn, Opstrømsdybde.Opstrømsdybde, Ledning.NedstroemKnudeID, Nedstrømsdybde.Nedstrømsdybde, Knude_1.Knudenavn, Delledning.Laengde, Delledning.Handelsmaal, K_LedningMateriale.Beskrivelse, TVObs.TVObsKode, TVObs.TVObsKlasse, TVObs.Type1, TVObs.Type2
    FROM RB_2-4
    UNION
    SELECT Ledning.OpstroemKnudeID, Knude.Knudenavn, Opstrømsdybde.Opstrømsdybde, Ledning.NedstroemKnudeID, Nedstrømsdybde.Nedstrømsdybde, Knude_1.Knudenavn, Delledning.Laengde, Delledning.Handelsmaal, K_LedningMateriale.Beskrivelse, TVObs.TVObsKode, TVObs.TVObsKlasse, TVObs.Type1, TVObs.Type2
    From DE_2-4;
    Click image for larger version. 

Name:	Union1.jpg 
Views:	8 
Size:	111.8 KB 
ID:	24132

    I need to add 4-5 queries into one. Queries like the ones shown in the picture.

    I can't quite get it too work.
    Last edited by FoolzRailer; 03-21-2016 at 01:13 AM. Reason: Added image.

  4. #4
    FoolzRailer is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    51
    Almost figured it out. Apparently we may not put "-" in a query name. But I still got a different result from what i wanted. It now merged all the queries, but instead of giving the correct Knude.Knudenavn, it gives RB_2_4.KnudeKnudenavn, which isn't present in any of the other queries, hence the empty column :/

    Code:
    SELECT  *
    FROM RB_2_4
    UNION  ALL
    SELECT  *
    FROM OB_2_4
    UNION  ALL
    SELECT  *
    FROM PF_2_4
    UNION  ALL
    SELECT  *
    FROM DE_3_4
    UNION  ALL
    SELECT  *
    FROM FS_2_4
    UNION ALL
    SELECT  *
    FROM IS_2_4;
    If instead of writing Select *, I write the individual column names (which are the same for each of the 6 queries I'm joining) it gives an error in FROM sentence.

    Edit: It now works, in the original queries, I have given the field a new name and that apparently fixed it. So yaiii!
    Last edited by FoolzRailer; 03-21-2016 at 02:05 AM. Reason: Fixed it.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding dates to an invoice using separate form
    By gebmiller1984 in forum Forms
    Replies: 1
    Last Post: 11-12-2015, 02:42 PM
  2. Replies: 2
    Last Post: 08-13-2014, 11:42 PM
  3. Replies: 5
    Last Post: 03-03-2014, 11:07 PM
  4. count blank colums in crosstab query
    By survivo01 in forum Queries
    Replies: 6
    Last Post: 04-13-2012, 01:37 PM
  5. adding record by using separate form
    By jacek.w.bak in forum Forms
    Replies: 1
    Last Post: 09-11-2011, 06:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums