|
Question : Conditional Concatenation in a Query
|
|
To simplify things, let's say I have a table containing 2 columns. Column 1 contains a character prefix. Column 2 contains numbers. Here is an example of some values the table might contain:
Column 1 Column 2 A 100 A 200 B 300 C 700
Using a SELECT query, I want to concatenate the values in Column 1 and Column 2 except for when the value in Column 1 is 'B'. If the value in Column 1 is 'B', then do not concatenate that row. Just show the Column 2 value in the query results for 'B' records. Here are the expected query results using the values I listed above:
A100 A200 300 C700
Notice how with the 'B' record, it does not get concatenated. Only the Column 2 value is included in the query results for 'B' records. In other words, if value in Column 1 equals 'B', do not concatenate. Only display the Column 2 value for 'B' records. All other records, concatenate.
|
|
Answer : Conditional Concatenation in a Query
|
|
select Column1, iif([Column1]="B", [Column2], [Column1]&[Column2]) AS YourColumnName from yourtable
hth
|
|
|
|