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)
 sql ?

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,000
111222333 LOUIS M LOFRANCO AND $10,000

or

222333444 WILLIAM M LANE TR FBO $10,000
222333444 WILLIAM M LANE TR UA SEP 15 92 WILLIAM M $5,000

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-08-17 : 11:23:02
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
Go to Top of Page

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,000

quote:
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


Go to Top of Page

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
Go to Top of Page

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


Go to Top of Page
   

- Advertisement -