Click here to Skip to main content
15,897,273 members
Home / Discussions / Database
   

Database

 
AnswerRe: Iif() statement usage problem Pin
riced10-Apr-09 4:11
riced10-Apr-09 4:11 
Questioncan I use '+=' in a datarow Pin
Maverickcool9-Apr-09 21:52
Maverickcool9-Apr-09 21:52 
AnswerRe: can I use '+=' in a datarow Pin
Mycroft Holmes9-Apr-09 22:25
professionalMycroft Holmes9-Apr-09 22:25 
AnswerRe: can I use '+=' in a datarow Pin
Colin Angus Mackay10-Apr-09 8:15
Colin Angus Mackay10-Apr-09 8:15 
GeneralRe: can I use '+=' in a datarow Pin
Maverickcool10-Apr-09 10:36
Maverickcool10-Apr-09 10:36 
QuestionOracle 11g Express Database? (I need TransactionScope support) Pin
devvvy9-Apr-09 17:07
devvvy9-Apr-09 17:07 
QuestionHow to select first n characters using stored procedure Pin
Meax9-Apr-09 8:04
Meax9-Apr-09 8:04 
AnswerRe: How to select first n characters using stored procedure Pin
Mycroft Holmes9-Apr-09 22:26
professionalMycroft Holmes9-Apr-09 22:26 
GeneralRe: How to select first n characters using stored procedure Pin
Meax10-Apr-09 3:58
Meax10-Apr-09 3:58 
GeneralRe: How to select first n characters using stored procedure Pin
Ramke16-Apr-09 0:05
Ramke16-Apr-09 0:05 
AnswerRe: How to select first n characters using stored procedure Pin
Ashfield12-Apr-09 4:31
Ashfield12-Apr-09 4:31 
QuestionDuplicate Rows Pin
Saiyed Alam9-Apr-09 4:50
Saiyed Alam9-Apr-09 4:50 
AnswerRe: Duplicate Rows Pin
Rob Philpott9-Apr-09 5:25
Rob Philpott9-Apr-09 5:25 
GeneralRe: Duplicate Rows Pin
Saiyed Alam9-Apr-09 6:49
Saiyed Alam9-Apr-09 6:49 
Questioncursor goes in to infinit loop......... Pin
pranavcool9-Apr-09 0:28
pranavcool9-Apr-09 0:28 
AnswerRe: cursor goes in to infinit loop......... Pin
Rob Philpott9-Apr-09 0:56
Rob Philpott9-Apr-09 0:56 
QuestionCan Predictive Analysis be done in SQL Server 2005? Pin
sunit_828-Apr-09 23:47
sunit_828-Apr-09 23:47 
QuestionHow to intergrate 2 table Pin
cocoonwls8-Apr-09 18:28
cocoonwls8-Apr-09 18:28 
AnswerRe: How to intergrate 2 table Pin
Kevin Horgan8-Apr-09 20:39
Kevin Horgan8-Apr-09 20:39 
GeneralRe: How to intergrate 2 table Pin
cocoonwls8-Apr-09 21:32
cocoonwls8-Apr-09 21:32 
GeneralRe: How to intergrate 2 table Pin
cocoonwls8-Apr-09 21:33
cocoonwls8-Apr-09 21:33 
GeneralRe: How to intergrate 2 table Pin
Kevin Horgan9-Apr-09 8:02
Kevin Horgan9-Apr-09 8:02 
Hi Cocoonwis,

You need to change the GROUP BY clause so it does not include the Amount fields.

Try this instead...

SELECT
t1.AID,
t1.CODE,
MAX(distinct(t1.TYPE) as t1Type),
SUM(t1.Amount) as t1Amount,
COALESCE(SUM(t2.Amount),0)
FROM t1
left outer join t2
on t1.AID = t2.ID
group by t1.AID,t1.CODE

Good luck,

Kevin

On Apr 9, 2009, at 9:17 AM, The Code Project forums wrote:


Hi Kevin,

Thanks for your help.I got it right now Smile | :)
But i have another question about it, if the records are duplicated in t1, and also t2. How could i sum the amount in t1.Amount and t2.Amount. Example there are 2 record A1 in t1, then i would like to sum them.Also in t2, i would like to sum the amount which have the same id.

I have try in my database, it dosen't SUM for me if i write like :

SELECT
t1.AID,
t1.CODE,
MAX(distinct(t1.TYPE) as t1Type),
SUM(t1.Amount) as t1Amount,
COALESCE(SUM(t2.Amount),0)
FROM t1
left outer join t2
on t1.AID = t2.ID
group by t1.AID,t1.CODE,t1.Amount,t2.Amount

thanks in advance
cocoonwls
GeneralRe: How to intergrate 2 table Pin
cocoonwls10-Apr-09 0:34
cocoonwls10-Apr-09 0:34 
GeneralRe: How to intergrate 2 table Pin
Kevin Horgan10-Apr-09 1:05
Kevin Horgan10-Apr-09 1:05 
QuestionHow to create encrypted trigger Pin
azad yadav8-Apr-09 17:51
azad yadav8-Apr-09 17:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.