0

I have a database and need to generate a report from the tables that I have been provided with.

However, the data source query that I am using -while in essence it works fine- is producing duplicates due to the "Parameter" and "Op Parameter" fields (each can be one of two values for each unique tag).

DB Illustration

What I would like to do is take each Parameter, each Op Parameter, and their values and tag them on as new fields for the unique tag (e.g., 'AI17611A') so that each tag is only shown once with all parameters.

Is this possible? If so, how would I go about it?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
ScottishTapWater
  • 3,656
  • 4
  • 38
  • 81

1 Answers1

0

If you want a new field for each possible value of [Op Parameter] then you could use an aggregation (GROUP BY) query, e.g., for sample table

[so38830066]

ID  Tag       Parameter  Op Parameter
--  --------  ---------  ------------
 1  AI17611A  HLPR       HLOP        
 2  AI17611A  HLPR       HHAOPT      
 3  AI17611B  HLPR       HLOP        
 4  AI17611C  HLPR       HHAOPT      

the query

SELECT 
    so38830066.Tag, so38830066.Parameter, 
    Min([Op Parameter]='HLOP') AS isHLOP, 
    Min([Op Parameter]='HHAOPT') AS isHHAOPT
FROM so38830066
GROUP BY so38830066.Tag, so38830066.Parameter;

produces

Tag       Parameter  isHLOP  isHHAOPT
--------  ---------  ------  --------
AI17611A  HLPR           -1        -1
AI17611B  HLPR           -1         0
AI17611C  HLPR            0        -1

You could do the same thing for multilple values of [Parameter] (e.g., create an [isHLPR] field) and then just GROUP BY [Tag].

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418