Concatenate 2 rows in a complex SQL query

后端 未结 1 1404
野性不改
野性不改 2021-01-23 15:30

I\'m using MS-Access 2003 with the query creator. I select everything from one table (FaitsSaillants), then one specific row (WHERE VARIABLE=\'TitreMandat\'

相关标签:
1条回答
  • 2021-01-23 16:23

    How about:

    PARAMETERS [CurrAxe] TEXT ( 255 ), [CurrOTP] TEXT ( 255 ), [CurrClient] TEXT (
    255 ), [StartDate] DATETIME, [EndDate] DATETIME;
    
    SELECT q.Projet, *
    FROM   (faitssaillants f
    LEFT JOIN employes e
    ON f.utilisateur = e.cip)
    INNER JOIN (
    SELECT s1.otp,
         [s1].[valeur] & "," & [s2].[valeur] AS Projet
    FROM   (
      SELECT otp, valeur
      FROM   tb_sommaire
      WHERE  [variable] = 'TitreMandat') AS s1
    INNER JOIN (
       SELECT otp, valeur
       FROM   tb_sommaire 
       WHERE  [variable] = 'NomInstallation') AS s2
    ON s1.otp = s2.otp) q
    ON f.otp = q.otp
    WHERE f.otp  = [currotp] 
    AND f.client LIKE [currclient] 
    AND f.axe LIKE [curraxe] 
    AND Datevalue([dateinsertion]) 
        Between [startdate] And [enddate] 
    ORDER  BY f.dateinsertion DESC; 
    

    It is always best to avoid referencing all fields as *. Fields (columns) should be listed by name.

    The above depends on creating a derived table that groups rows from tb_sommaire by Otp. You can cut and paste the derived table into a query design screen (sql view) to check that the rows returned are as expected.

    0 讨论(0)
提交回复
热议问题