Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Merging fields together

Author  Topic 

jamiesw
Starting Member

6 Posts

Posted - 2014-02-25 : 14:27:32
Hi there
i have some sql that i also need to merge several fields into one. any helpers please

I need to merge all the columns i have the CASE against so it will output a coloumn with the values.
thanks
jamie

SELECT SUM(total) AS SumOftotal, Code, tbl_years_lookup.year,
CASE FSG_UK
WHEN 0 THEN ''
WHEN 1 THEN 'UK'
END AS UK,
CASE FSG_Int
WHEN 0 THEN ''
WHEN 1 THEN 'INT'
END AS INT,
CASE FSG_EU
WHEN 0 THEN ''
WHEN 1 THEN 'EU'
END AS EU,
CASE FSG_SC
WHEN 0 THEN ''
WHEN 1 THEN 'SC'
END AS SC,
title, modename, YearofProg
FROM tbl_Background_Details INNER JOIN
tbl_years_lookup ON tbl_Background_Details.Year_id = tbl_years_lookup.years_id
GROUP BY
tbl_Background_Details.Year_id,
tbl_Background_Details.Code,
tbl_Background_Details.Title,
tbl_Background_Details.modename,
tbl_Background_Details.YearofProg,
tbl_Background_Details.Recruitment_Year,
tbl_Background_Details.FSG_UK,
tbl_Background_Details.FSG_Int,
tbl_Background_Details.FSG_EU,
tbl_Background_Details.FSG_SC,
tbl_years_lookup._year
HAVING (tbl_Background_Details.code = @code)
ORDER BY tbl_Background_Details.Code

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-02-25 : 19:00:23
I'm not clear on what you want as an output. Can you show an example? Are you just trying to concatenate the UK, INT, EU and SC columns together?

===============================================================================
There are two kinds of light -- the glow that illuminates, and the glare that obscures. -James Thurber (1894-1961)
Go to Top of Page

jamiesw
Starting Member

6 Posts

Posted - 2014-02-26 : 03:10:03
Thanks for replying. The output would be something like;
i am getting stuck due to the CASE statements i have to change the bit field to string.

SumOfTotal,Code,Year,FSG_Grp,title,modename,YearofProg
15, AV34, 2012, UK,My Title, Mode 1, 2013
12, AV78, 2011, INT, My Title, Mode 2, 2012
12, AV67, 2013, SC, My Title, Mode 3, 2014
45, AV23, 2009, EU, My Title, Mode 1, 2010
Go to Top of Page
   

- Advertisement -