On 01 Dec 2012 07:05, Richard Schoen wrote:

One other thing I forgot to mention in my case is that I need to
pick FieldName based on a LIKE ends with condition (like '%ield1'),
not an equal condition the way Eric showed me. <<SNIP>> I just
changed the CASE statement to a LIKE and got what I needed. <<SNIP>>

Here's a real world example of how it currently looks in testing:

select FFORMID,
char(max(Case when FFIELDNAM like '%Fld1'
then trim(ffieldval) end),30) as fld1
group by fformid

That *may* be fine, given care is taken with the value-pair naming; i.e. if always there is sure to be only one matching row. The use of the statement with the MAX aggregate depends on there being exactly one match for the name. If ever the LIKE predicate yields more than one match, then which field\pair value is chosen is questionable; perhaps unintended results:

create table qtemp/f (id dec, fn varchar(15), fv varchar(50))
insert into qtemp/f values
( 1, 'IntendedFld1', 'Intended Value')
, ( 1, 'BogusFld1' , 'Bogus Value')
, ( 1, 'ShamFld1' , 'Sham Value')

Using MAX on the above data, for example, would yield the 'Sham Value' instead of the 'Intended Value' for the column identified by the "AS FLD1" column. Of course using the MIN instead, has the same issue, yielding the undesirable 'Bogus Value'.

This thread ...

Return to Archive home page | Return to MIDRANGE.COM home page