Note that there are some explanatory texts on larger screens.

plurals
  1. POConcatenate 2 rows in a complex SQL query
    primarykey
    data
    text
    <p>I'm using MS-Access 2003 with the query creator. I select everything from one table (<code>FaitsSaillants</code>), then one specific row (<code>WHERE VARIABLE='TitreMandat'</code>) from another table (<code>tb_SOMMAIRE</code>). I want to select another row from that second table and concatenate it.</p> <h2>The query</h2> <pre class="lang-sql prettyprint-override"><code>PARAMETERS [CurrAxe] Text ( 255 ), [CurrOTP] Text ( 255 ), [CurrClient] Text ( 255 ), [StartDate] DateTime, [EndDate] DateTime; SELECT tb_SOMMAIRE.Valeur AS Projet, tb_SOMMAIRE.VARIABLE, * FROM (FaitsSaillants LEFT JOIN Employes ON FaitsSaillants.Utilisateur = Employes.CIP) INNER JOIN tb_SOMMAIRE ON FaitsSaillants.OTP = tb_SOMMAIRE.OTP WHERE (((FaitsSaillants.OTP)=[CurrOTP]) AND ((FaitsSaillants.Client) Like [CurrClient]) AND ((FaitsSaillants.Axe) Like [CurrAxe]) AND ((DateValue([DateInsertion]))&gt;=[StartDate] AND (DateValue([DateInsertion]))&lt;=[EndDate]) AND ((tb_SOMMAIRE.VARIABLE)='TitreMandat')) ORDER BY FaitsSaillants.DateInsertion DESC; </code></pre> <p>This query does add the <code>tb_SOMMAIRE.Valeur</code> field where the IDs (<code>OTP</code> field) match and where <code>tb_SOMMAIRE.VARIABLE='TitreMandat'</code>. It works like a charm. However, I want to add another row to the <code>tb_SOMMAIRE</code> results. I would like to get the row where <code>VARIABLE='TitreMandat'</code> (that part is actually working) and the row where <code>VARIABLE='NomInstallation'</code>. I will get 2 rows and I want those 2 rows to be concatenated and displayed when I ask for <code>Projet</code> (<code>tb_SOMMAIRE.Value as Projet</code>). Both rows' <code>OTP</code> (IDs) are the same as the one selected in <code>FaitsSaillants</code>.</p> <p>Sorry if it's in French.</p> <h2>Tables' structure</h2> <p>FaitsSaillants</p> <blockquote> <pre><code>Index AutoNumber Projet Text Axe Text Client Text OTP Text FaitSaillant Memo DateInsertion Date Utilisateur Text </code></pre> </blockquote> <p>tb_SOMMAIRE</p> <blockquote> <pre><code>OTP Text VARIABLE Text Valeur Text </code></pre> </blockquote> <h2>Data example</h2> <p>tb_SOMMAIRE</p> <blockquote> <pre><code>OTP VARIABLE Valeur UGPSW NomInstallation PosteNemiscau UGPSW TitreMandat oscilloperturbographe UGPSW RespIng CU9656 GWIHK NomInstallation AnotherInstallation GWIHK TitreMandat Anytitle GWIHK Responsable ImportantPerson </code></pre> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload