Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Sql query ? left outer join and sum ?

$
0
0

Hello 

I have below query. there are Same records if i dont use SUM. so when i use sum, i do sum same records again. How can i sum only records in 

 LG_031_01_STFICHE AS STFIC ?
SELECT     SUM(STFIC.TOTALDISCOUNTED) AS X, SUM(STFIC.TOTALDISCOUNTS) AS DISCOUNTED, SUM(STFIC.NETTOTAL) AS Expr1, SUM(STFIC.GROSSTOTAL) AS Expr1
FROM      LG_031_01_STLINE AS STRNS WITH (NOLOCK)  LEFT OUTER JOIN
                       LG_031_01_STFICHE AS STFIC WITH (NOLOCK)  ON STRNS.STFICHEREF = STFIC.LOGICALREF LEFT OUTER JOIN
                      LG_031_CLCARD AS CLNTC WITH (NOLOCK) ON STRNS.CLIENTREF = CLNTC.LOGICALREF LEFT OUTER JOIN
                      LG_031_ITEMS AS ITMSC WITH (NOLOCK) ON STRNS.STOCKREF = ITMSC.LOGICALREF
WHERE     (STRNS.SOURCEINDEX IN (0, 1, 2)) AND (STFIC.DATE_ >= CONVERT(dateTime, '8-1-2013', 101)) AND (STFIC.DATE_ <= CONVERT(dateTime, '8-31-2013', 101)) AND 
                      (STFIC.CANCELLED = 0) AND (CLNTC.SPECODE LIKE '24İzm') AND (STFIC.TRCODE IN (8)) AND (STFIC.DEPARTMENT IN (0)) AND (STFIC.BRANCH IN (0)) AND 
                      (STFIC.FACTORYNR IN (0)) AND (STRNS.CPSTFLAG <> 1) AND (STRNS.LINETYPE IN (0, 1, 5, 6, 8, 10)) AND (STFIC.TRCODE IN (8))


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>