Hi and welcome to the forums. It is considered best practice to post ddl and sample data so that we can work directly on your problem. Since this is your very first post I created it for you this time so you can what I mean. You can read more about best practices by following the link in my signature.
Here is an example of what you should include in your future posts.
create table #Something
select 100, 'A', 1, 20 union all
select 101, 'B', 2, 30 union all
select 100, 'A', 3, 40
drop table #Something
The challenge you are facing is best handled using a cross tab. This is very common and is pretty simple to deal with. There are two types of cross tabs, static and dynamic. Based on your sample data you might be able to use the static version.
Here is how you could do the static version.
select IntRecpieID, strName,
MAX(case when intMealtypeID = 1 then Total end) as Total1,
MAX(case when intMealtypeID = 2 then Total end) as Total2,
MAX(case when intMealtypeID = 3 then Total end) as Total3
group by IntRecpieID, strName
You can read more about cross tabs by following the links in my signature. Hope this works for you.
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter
.Cross Tabs and Pivots, Part 1 – Converting Rows to Columns Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs Understanding and Using APPLY (Part 1)Understanding and Using APPLY (Part 2)