Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi I want sum of two Same Columns.
My Query is as Follows

SQL
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
Comments
OriginalGriff 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 30-Apr-13 5:53am    
Yep Sure.Next time i will improve my question.
Prasad Khandekar 30-Apr-13 1:21am    
Try removing ORRMCTG from ORDER BY.

1 solution

Remove ORRMCTG column from your query and you'll get desired results.
SQL
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
 
Share this answer
 
Comments
Member 9799439 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900