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 2000 Forums
 Transact-SQL (2000)
 query question ( m to m )

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2006-09-13 : 12:06:47
I have two tables: data and note


Data table
Name Inc Amt Key
John Med 200 1
John Med 300.89 1
John Med 333 3
John MDD 234 4
Mary Mec 345,88 5
Mary Mec 111 5




Note table

Key Desc
1 6 month pre-xting
1 Payor is secure
3 Spoke to elis
4 Recreation Receipt
5 No records for this person
5 Need to call 000-0000


I would like to return the output looks like below: I would like to group the data table by name, Inc, sum (amt) and attach the concatenated “Desc”

Name Inc Amt Desc
John Med 833.89 6 month pre-xting, Payor is secure, Spoke to elis
John Med 333 Recreation Receipt
Mary Mec 145.88 No records for this person, Need to call 000-0000


nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-13 : 12:56:39
Create a function to get the concatenated descriptions from the note table and call it in the select statement with the key.
The aggregate should be easy - but why do you include key 3 with 1 for john med and also separately.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -