Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2005
    Posts
    71

    Unanswered: How to create and retrieve a calculated column

    Table: Names
    Columns: Name_RID char(10)
    Name_Type smallint
    Name_Last char(50)
    Name_First char(25)
    Name_MI char

    I have search for and see how to put the columns for the last, first mi together (Name_Last + ', ' + Name_First + ' ' + Name_MI) as Name
    But how can I test the value of the Name_Type field to determine how the Name column looks
    if Name_Type = 1 then
    Name = (Name_Last + ', ' + Name_First + ' ' + Name_MI)
    else
    Name = Name_Last

    The Name_Type represents Individual versus an Entity
    0,ABC Pipeline,,
    1,Williams, John,A

  2. #2
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Have you looked at the CASE statement?

    -- This is all just a Figment of my Imagination --

  3. #3
    Join Date
    Mar 2005
    Posts
    71

    I didnt even know there was a CASE statement...

    I will look into it thanks...

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Look no further

    Code:
    SELECT CASE WHEN Name_Type = 1  THEN Name_Last + ', ' + Name_First + ' ' + Name_MI	
    				ELSE Name_Last
    	END AS [Name]
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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