Alpha Video Training
Results 1 to 3 of 3

Thread: SQL Question

  1. #1
    Member
    Real Name
    Donna Frederick
    Join Date
    Jun 2011
    Posts
    198

    Default SQL Question

    Suppose I have a CLIENT table with a primary contact and a secondary contact and I need to produce mailing labels or emails for each contact. Can that be done with a SQL Select Statement? I've done things like this in the past by creating temporary tables, but I wanted to see if I could improve upon that. Can it be done without creating a second table with contacts? Tried outer join without success.

    CLIENT TABLE
    FIELDS: CLIENTNAME, CLIENTID, CONTACT1, ADDRESS1, CITY1, STATE1, ZIP1, CONTACT2, ADDRESS2, CITY2, STATE2, ZIP2

    QUERY TO PRODUCE: CONTACT, ADDRESS, CITY, STATE, ZIP (and ADDRESS IS NOT NULL)

    I am using MSACCESS tables.

    Thanks

  2. #2
    Member
    Real Name
    Jeff
    Join Date
    May 2008
    Posts
    149

    Default Re: SQL Question

    It appears this is what you may be looking for

    https://msdn.microsoft.com/en-us/library/ethytz2x.aspx

  3. #3
    Member
    Real Name
    Donna Frederick
    Join Date
    Jun 2011
    Posts
    198

    Default Re: SQL Question

    Found that a simple UNION solved the normalization problem. Also, learned about a relatively new command UNPIVOT that does the job also. See
    http://weblogs.sqlteam.com/jeffs/archive/2008/04/23/unpivot.aspx

    SELECT CLIENTID, CONTACT1 AS CONTACT, ADDRESS1 AS ADDRESS, CITY1 AS CITY, STATE1 AS STATE, ZIP1 AS ZIP
    FROM CLIENT
    UNION
    SELECT CLIENTID, CONTACT2 AS CONTACT, ADDRESS2 AS ADDRESS, CITY2 AS CITY, STATE2 AS STATE, ZIP2 AS ZIP
    FROM CLIENT

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •