The solution to your problem does involve a join (like Rudy mentioned in the first reply).
The trick here is that we don't ALWAYS want to join to the other table. Unfortunately, you cannot pick and choose when to join. You either join, or you don't. In this case, you can perform a left join to solve your problem. With a left join, you will get all the records from the 'left' table, and only matching records from the right table. If there is not a corresponding match in the 'right' table, NULL will be returned for every column. We can use this to our advantage. By putting enough conditions on the join, we can cause the query to ONLY return (i.e. match) records that we want to use. If there is no match, we want to use data from the original table. If there is a match, then use records from the second table.
So, the question then becomes, how do we choose. Like I said earlier, by left joining (and putting enough conditions on the join), we will get NULLs from the second table. When there is a NULL in the second table, we want to use the data from the first.
You never mentioned what the table names were, so in this example, I am using Table1 and Table2. Obviously, you will need to change the table names to match your real names.
Code:
Select Table1.Descr,
Table1.Type,
Table1.Detail,
Coalesce(Table2.GLI_DESCRIPTION, Table1.Answer) As Answer
From Table1
Left Join Table2
On Table1.Type = 'GEN'
And Table1.Answer = Table2.GLI_SEQU
I want to mention a couple things here, for clarification purposes.
First, notice the join condition. The 'Answer' column from table1 joins with the GLI_SEQU column of table 2. That's obvious. However, I added Table1.Type = 'GEN'. This ensures that we will only match records in the second table when the Type column of Table1 is 'GEN'.
Second, notice the Coalesce function. This function will return the first Non-Null value passed to it. Remember earlier when I said that NULL's will be returned when there is no match? Well, in that case Table2.GLI_DESCRIPTION will be null. The Coalesce function will then return the Table1.Answer value.
Does this make sense?
-George
"the screen with the little boxes in the window." - Moron