Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
Hi
I want sum of two Same Columns.
My Query is as Follows
 
SELECT  OMTC,OMYY,OMNO,ODSR,OMCMCD,OMLMGCST,ODSALPRC,ORRMCTG,SUM(ORSALVAL) as total
FROM ORDMST INNER JOIN ORDDSG ON OMTC=ODTC AND OMYY=ODYY AND OMCHR=ODCHR AND OMNO=ODNO
INNER JOIN ORDRM ON ODTC=ORTC AND ODYY=ORYY AND ODCHR=ORCHR AND ODNO=ORNO AND ODSR=ORSR
where  omtc='qt' and omyy='13' and omchr='KPS' and omno='174' AND ODSR=2 AND ORRMCTG NOT IN ('d','C')
GROUP BY ODSR,ORRMCTG,OMTC,OMYY,OMNO,OMCMCD,OMLMGCST,ODSALPRC
 
Result :
QT 13 174 2 KP029 1500 98.53 S 3.942
QT 13 174 2 KP029 1500 98.53 X 9.072
 
Expected Result :
QT 13 174 2 KP029 1500 98.53 13.014
Posted 29-Apr-13 20:07pm
Comments
OriginalGriff at 30-Apr-13 1:16am
   
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Member 9799439 at 30-Apr-13 5:53am
   
Yep Sure.Next time i will improve my question.
Prasad Khandekar at 30-Apr-13 1:21am
   
Try removing ORRMCTG from ORDER BY.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Remove ORRMCTG column from your query and you'll get desired results.
SELECT  OMTC
       ,OMYY
       ,OMNO
       ,ODSR
       ,OMCMCD
       ,OMLMGCST
       ,ODSALPRC
       ,SUM(ORSALVAL) as total
FROM ORDMST 
INNER JOIN ORDDSG ON OMTC=ODTC AND OMYY=ODYY AND OMCHR=ODCHR AND OMNO=ODNO
INNER JOIN ORDRM ON ODTC=ORTC AND ODYY=ORYY AND ODCHR=ORCHR AND ODNO=ORNO AND ODSR=ORSR
 
WHERE omtc='qt' AND omyy='13' AND omchr='KPS' AND omno='174' AND ODSR=2 
      AND ORRMCTG NOT IN ('d','C')
GROUP BY ODSR,OMTC,OMYY,OMNO,OMCMCD,OMLMGCST,ODSALPRC
  Permalink  
Comments
Member 9799439 at 30-Apr-13 5:53am
   
@Oshtri Deka : Thank You So Much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 215
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 159
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100