On Mon, Jan 26, 2009 at 5:34 PM, Kenneth Kixmoeller <[email protected]> wrote: > OK, I'm working on this in a SQL statement (MySQL): > > Have 3 fields from 2 tables which need to be combined to make up a > single field address field in an export file. The three fields are: > - location.address1 > - location.address2 > - person_location.mailcode > > The mail_code belongs to the instance of person's belonging to a > place, not the place. Different people in the same facility have > different mailcodes. Good normalization, IMO. (Besides, not possible > to change the DB design even if you disagree.) > > The format of the field in the export is this: > > address1^address2, but only if address2 is populated, in which case > address1 without the ^ > > Since I don't have any place to put the mailcode, I'll concatenate it > to address2. However, as in everything in this crazy-a$$ business we > are in, it isn't so simple, as any of the three could be populated, > empty, or NULL. In MySQL, if you try to concatenate a string and any > part of it is NULL, the result is NULL. > > So, before dealing with the Null thing, I had: > > select > if(length(concat(address,mailcode`))=0, > address1, > concat(address1,'^',address2`,'-',mailcode`)) > as concat_addr, > <rest of it>
select case when ThisCondition then ThisValue else ThatValue end as MyOutput or Select Case ColumnOrVariable when ThisCondition then ThisValue when ThatCondition then ThatValue etc. end as MyOutput So why didn't you present your VFP code and we would have T-SQLed it for you. Select case when address,mailcode ='' then address1 end as Output1 , ltrim(rtrim(address1))+'^'+ ltrim(rtrim(address2))+'-'+mailcode concat_addr blablabla > I am working on a CASE statement as we 'speak', but there seem to be > so frickin' many possibilities, that I am having a hard time wrapping > my head around a single statement to encompass the possibilities. > before I drive myself crazier, am I missing a more obvious approach? > > I could have had this done in about 12 seconds if I had a good- > ol' (but much maligned) VFP cursor... > > Ken > [excessive quoting removed by server] _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/[email protected] ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

