Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Joining Across 3 Tables Returning Null Values

$
0
0

I am trying to write a query that will give me name, #of sales, #of contacts, %sales to contacts, volume sold, hours...etc.

I have to pull this information from three different tables, but for some reason the query is returning NULL values for time when the agent doesn't have any sales volume. Thanks for looking.

This is what I have

Text
SELECT UPPER (CL.CREDITTO) AS NAME,ISNULL(CL.SALES,0)AS SALES,CL.CONTACTS, CAST(CL.SALES/CL.CONTACTS AS DECIMAL) AS TURN_RATIO, ISNULL(S.TOTAL,0) AS VOLUME, CAST(H.HOURS AS DECIMAL (8,2)) AS HOURS,CAST (CL.CONTACTS/H.HOURS AS DECIMAL (8,2))AS CPH, CAST(S.TOTAL/H.HOURS AS DECIMAL(8,2)) AS HOURLYFROM( SELECT AGENT, SUM (NPT.SALEAMT) AS TOTAL FROM CLIENTS.DBO.NPTSALES NPT WHERE START  '2015-10-02' GROUP BY AGENT) SLEFT JOIN( SELECT AGENTID, SUM (DATEDIFF(ss, LOGON,ISNULL (LOGOFF,GETDATE()))/3600.0)AS HOURS...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



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