CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2001
    Location
    New Jersey
    Posts
    312

    tricky statement...

    This is my problem.

    I have 10 different codes in a table.

    Another table has descriptions of the codes.

    I am trying to come up with a select statement than will change the codes to their descriptions per row. Each row has 10 different codes.

    Not sure how I do this!
    Last edited by Lord Zarm; April 12th, 2004 at 02:18 PM.
    http://www.dewgames.com
    Shareware and Free games!

  2. #2
    Join Date
    Nov 2003
    Location
    Seattle, WA
    Posts
    265
    Quick question. Why not just put them both in one table.. Would make it a lot simpler for you.
    "Lose it? It means go crazy...nuts...insane...bonzo...no longer in possession of one's faculties...3 fries short of a happy meal...WACKO!!!"

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Or, using two tables

    Say table one (code) is like
    codekey,CodeText, descriptionId
    and the table two (description) is
    descriptionId, DescriptionText
    then your select is:
    Code:
    select CodeText,DescriptionText
    from
    Table1, Table2
    where 
    table1.descriptionId=table2.descriptionId
    and table1.descriptionId is not null
    The above will list all related itmes, skipping those for which
    you do not have a value in both

    If you want, you can use a join query:
    Code:
    select CodeText,DescriptionText
    from
    Table1
    inner Join
    Table2
    on
    Table2.descriptionId=Table1.descriptionId
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Feb 2001
    Location
    New Jersey
    Posts
    312
    The problem is that all of these codes are different columns in one row. So I need to match these codes with a description from one other table.

    I cant change the table layout. I didnt design it and I am stuck with it and I really want to kill the person who designed it with these arrays of values. Its killing me.
    http://www.dewgames.com
    Shareware and Free games!

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    Do you really want/need to replace them, or can you just display the descriptions (multiple per row).

    In general keeping the descriptions in a seperate table is a good idea (data normalization). Kind of a moot point since you cant change the schema in any case...

    Code:
    SELECT Table2.ID, 
    Table1_1.Descript AS D1, Table1_2.Descript AS D2, Table1_3.Descript AS D3, Table1_4.Descript AS D4
    
    FROM
    (((Table2 INNER JOIN Table1 AS Table1_1 ON Table2.Code1 = Table1_1.Code) 
    INNER JOIN Table1 AS Table1_2 ON Table2.Code2 = Table1_2.Code) 
    IINNER JOIN Table1 AS Table1_3 ON Table2.Code3 = Table1_3.Code) 
    INNER JOIN Table1 AS Table1_4 ON Table2.Code4 = Table1_4.Code;
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured