Concatenate values in the same column.
hello guys, i've been searching day , didnt resolution.
i have query:
select c.cor_id, c.cor_description,
case month(tur_start) when 1 day(tur_start) end j,
case month(tur_start) when 2 day(tur_start) end f,
case month(tur_start) when 3 day(tur_start) end m,
case month(tur_start) when 4 day(tur_start) end a,
case month(tur_start) when 5 day(tur_start) end m,
case month(tur_start) when 6 day(tur_start) end j,
case month(tur_start) when 7 day(tur_start) end j,
case month(tur_start) when 8 day(tur_start) end a,
case month(tur_start) when 9 day(tur_start) end s,
case month(tur_start) when 10 day(tur_start) end o,
case month(tur_start) when 11 day(tur_start) end n,
case month(tur_start) when 12 day(tur_start) end d
v_turm t inner join course c on t.cor_id = c.cor_id
t.cor_id = 113 , year(tur_start) = 2011
that returns this:
cor_id cor_description j f m a m j j a s o n d
113 gestão estratégica null null null null 20 null null null null null null null
113 gestão estratégica null null null null null 6 null null null null null null
113 gestão estratégica null null null null null null 4 null null null null null
113 gestão estratégica null null null null null null null 1 null null null null
113 gestão estratégica null null null null null null null 22 null null null null
113 gestão estratégica null null null null null null null null 12 null null null
113 gestão estratégica null null null null null null null null null null 7 null
113 gestão estratégica null null null null null null null null null null 28 null
there way return like:
cor_id cor_description j f m a m j j a s o n d
113 gestão estratégica null null null null 20 6 4 1 , 22 12 null 7 , 28 null
this possible ?
select c.cor_id, c.cor_description, min(case month(tur_start) when 1 then day(tur_start) end) as j, min(case month(tur_start) when 2 then day(tur_start) end) as f, min(case month(tur_start) when 3 then day(tur_start) end) as m, min(case month(tur_start) when 4 then day(tur_start) end ) as a, min(case month(tur_start) when 5 then day(tur_start) end )as m, min(case month(tur_start) when 6 then day(tur_start) end )as j, min(case month(tur_start) when 7 then day(tur_start) end )as j, min(case month(tur_start) when 8 then day(tur_start) end )as a, min(case month(tur_start) when 9 then day(tur_start) end ) as s, min(case month(tur_start) when 10 then day(tur_start) end ) as o, min(case month(tur_start) when 11 then day(tur_start) end )as n, min(case month(tur_start) when 12 then day(tur_start) end ) as d from v_turm as t inner join course as c on t.cor_id = c.cor_id where t.cor_id = 113 and year(tur_start) = 2011 group by c.cor_id, c.cor_description
is. going assume there 1 record each cor_id, cor_description , month(tur_month)
russel loski, mcitp business intelligence developer , database developer 2008
SQL Server > SQL Server Integration Services
Comments
Post a Comment