-- Some sample data.
declare @Persons as Table (PersonId Int Identity,
AfricanAmerican Bit Null, Asian Bit Null, Hispanic Bit Null, NativeAmerican Bit Null, White Bit Null);
insert into @Persons (AfricanAmerican, Asian, Hispanic, NativeAmerican, White) values
(NULL, NULL, NULL, NULL, NULL),
(0, 0, 0, 0, 0),
(1, 0, 0, 0, 0),
(0, 1, 0, 0, 0),
(0, 0, 1, 0, 0),
(0, 0, 0, 1, 0),
(0, 0, 0, 0, 1),
(0, 1, 1, 1, NULL);
-- Display the results.
select PersonId, AfricanAmerican, Asian, Hispanic, NativeAmerican, White,
Substring(Ethnicity, case when Len(Ethnicity) > 3 then 3 else 1 end,
case when Len(Ethnicity) > 3 then Len(Ethnicity) - 2 else 1 end) as Ethnicity
from (
select PersonId, AfricanAmerican, Asian, Hispanic, NativeAmerican, White,
case when AfricanAmerican = 1 then '/African American' else '' end +
case when Asian = 1 then '/Asian' else '' end +
case when Hispanic = 1 then '/Hispanic' else '' end +
case when NativeAmerican = 1 then '/Native American' else '' end +
case when White = 1 then '/White' else '' end as Ethnicity
from @Persons
) as Simone;
這將是更好地糾正你的正常化。人'1-n'種族 –
沒有選項... –