Friday, March 23, 2012

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,AHave you looked at the CASE statement?|||I will look into it thanks...|||Look no further

SELECT CASE WHEN Name_Type = 1 THEN Name_Last + ', ' + Name_First + ' ' + Name_MI
ELSE Name_Last
END AS [Name]sql

No comments:

Post a Comment