I made a couple of improvements. First I got rid of the Misc table because another poster gave me a solution to that syntax error.
Secondly, for casees of nonmatches I now use two columns
Detail0/2 Needed.....Detail0/2 FullName
With a non-match, the FullName will be empty but the first column should still populate. Here is the new version:
SELECT Important_0, [Detail0/4-Needed], [Detail0/1-Needed], [Detail0/2-Needed], A.FullName as [Detail0/2-FullName]
FROM
(
SELECT Important_0, FIRST(D.[Detail0/4-Needed]) as [Detail0/4-Needed], FIRST(D.[Detail0/1-Needed]) as [Detail0/1-Needed], FIRST(D.[Detail0/2-Needed]) as [Detail0/2-Needed]
FROM [Database] as D
WHERE Important_2 = @NumberToFind
GROUP BY Important_0
UNION ALL
SELECT Important_0, FIRST(D.[Detail0/4-Needed]) as [Detail0/4-Needed], FIRST(D.[Detail0/1-Needed]) as [Detail0/1-Needed], FIRST(D.[Detail0/2-Needed]) as [Detail0/2-Needed]
FROM [Database] as D
WHERE Important_1 = @NumberToFind
GROUP BY Important_0
) as Connections
LEFT JOIN AbbreviationsForDetails02Needed as A
ON A.Abbreviation = Connections.[Detail0/2-Needed]
Feel free to rollback to an older versoin of the query if you don't want to use the abbreviations table.
Secondly, for casees of nonmatches I now use two columns
Detail0/2 Needed.....Detail0/2 FullName
With a non-match, the FullName will be empty but the first column should still populate. Here is the new version:
SELECT Important_0, [Detail0/4-Needed], [Detail0/1-Needed], [Detail0/2-Needed], A.FullName as [Detail0/2-FullName]
FROM
(
SELECT Important_0, FIRST(D.[Detail0/4-Needed]) as [Detail0/4-Needed], FIRST(D.[Detail0/1-Needed]) as [Detail0/1-Needed], FIRST(D.[Detail0/2-Needed]) as [Detail0/2-Needed]
FROM [Database] as D
WHERE Important_2 = @NumberToFind
GROUP BY Important_0
UNION ALL
SELECT Important_0, FIRST(D.[Detail0/4-Needed]) as [Detail0/4-Needed], FIRST(D.[Detail0/1-Needed]) as [Detail0/1-Needed], FIRST(D.[Detail0/2-Needed]) as [Detail0/2-Needed]
FROM [Database] as D
WHERE Important_1 = @NumberToFind
GROUP BY Important_0
) as Connections
LEFT JOIN AbbreviationsForDetails02Needed as A
ON A.Abbreviation = Connections.[Detail0/2-Needed]
Feel free to rollback to an older versoin of the query if you don't want to use the abbreviations table.