So i have a small amount of SQL below.
SELECT DISTINCT
Id,
Date,
Name_Detail,
(SELECT CASE
WHEN (Name_Detail IN ('a1','a2') and Name_Detail IN ('d1','d2'))
THEN 'AUX'
ELSE
(CASE
WHEN Name_Detail IN ('d1','d2')
THEN 'DIN'
ELSE
(CASE
WHEN Name_Detail IN ('a1','a2')
THEN 'AUX'
ELSE 'NO'
END)
END)
END)
AS [Alias]
This gives the following results.
Id Date Name_Detail Alias
1 01/04/2013 d1 Din
1 01/04/2013 d2 Din
2 02/09/2013 a1 Aux
2 02/09/2013 a2 Aux
2 02/09/2013 d1 Din
2 02/09/2013 d2 Din
If i remove the name_detail part it then gives the below.
Id Date Alias
1 01/04/2013 Din
2 02/09/2013 Aux
2 02/09/2013 Din
This still however gives a duplicate line fore the AUX and the DIN for ID 2.
What i want it to follow is...
If the Name_Detail contain(s) a1 and(or) a2 its Alias is AUX.
If the Name_Detail contain(s) d1 and(or) d2 its Alias is DIN.
If the Name_Detail contain(s) a1 and(or) a2 AND d1 and(or) d2 its Alias is AUX.
So for the above data should result in 2 lines as id 1 has d1 and d2 so it shows the Alias as DIN and id 2 has d1,d2,a1,a2 so it shows the Alias as AUX.
Id Date Alias
1 01/04/2013 Din
2 02/09/2013 Aux