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.
| Author |
Topic |
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2011-08-17 : 11:18:24
|
| Hello,Please see my below examples, I want to know how can I write sql statement to get in one row of report for each account (same id, but name appear not in the same order or extra character...ect....Thanks,111222333 LOFRANCO, LOUIS M $10,000111222333 LOUIS M LOFRANCO AND $10,000or 222333444 WILLIAM M LANE TR FBO $10,000222333444 WILLIAM M LANE TR UA SEP 15 92 WILLIAM M $5,000 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2011-08-17 : 11:48:38
|
That 's my starting. My expected output as below:111222333 LOUIS M LOFRANCO $20,000 222333444 WILLIAM M LANE $15,000quote: Originally posted by Lamprey Is that your starting data or your expected output?Please see the following link on how to help us to help you:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
|
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-08-17 : 12:11:53
|
Since you didn't supply any information about your table (name, column names) basica DDL and DML to put data into your table, I jsut made a guess:SELECT ID_Column, MIN(Name_Column) AS <ColumnName>, SUM(Dollar_Amount_Column) AS <ColumnName>FROM <Table>GROUP BY ID_Column |
 |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2011-08-17 : 13:17:05
|
I was using max(name) function...I will try min to see if it work...the problem is i get $ column from difference tables so I do union query to get final answer, the result came of still more than one row for same id since it had difference payername for that id...Thanks,quote: Originally posted by Lamprey Since you didn't supply any information about your table (name, column names) basica DDL and DML to put data into your table, I jsut made a guess:SELECT ID_Column, MIN(Name_Column) AS <ColumnName>, SUM(Dollar_Amount_Column) AS <ColumnName>FROM <Table>GROUP BY ID_Column
|
 |
|
|
|
|
|
|
|