SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Merging fields together
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jamiesw
Starting Member

United Kingdom
6 Posts

Posted - 02/25/2014 :  14:27:32  Show Profile  Reply with Quote
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

Edited by - jamiesw on 02/25/2014 15:26:07

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1677 Posts

Posted - 02/25/2014 :  19:00:23  Show Profile  Reply with Quote
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

United Kingdom
6 Posts

Posted - 02/26/2014 :  03:10:03  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000