MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » December 2012

RE: Interesting SQL Question - Flatten Multiple Records into One Record



fixed

Chuck you are correct.

I don't know if I stated it, but my assumption would be to only use this technique for unique fields.

Regards,
Richard Schoen
RJS Software Systems Inc.
Where Information Meets Innovation
Document Management, Workflow, Report Delivery, Forms and Business Intelligence
Email: richard@xxxxxxxxxxxxxxx
Web Site: http://www.rjssoftware.com
Tel: (952) 736-5800
Fax: (952) 736-5801
Toll Free: (888) RJSSOFT
------------------------------

message: 4
date: Mon, 03 Dec 2012 10:33:28 -0600
from: CRPence <CRPbottle@xxxxxxxxx>
subject: Re: Interesting SQL Question - Flatten Multiple Records into
One Record

On 01 Dec 2012 07:05, Richard Schoen wrote:
<<SNIP>>

Note:
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
<<SNIP>>
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'.

--
Regards, Chuck







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

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact