dc

dc

  • NA
  • 663
  • 0

t-sql 2008 not returning all data

Sep 30 2012 5:51 PM
I am having a problem returning data from the query listed below from a sql server 2008 r2 database:

SELECT
G.Custid
,ISNULL(G.Count_Of_PAR,0)
,ISNULL(B.Count_Of_NPAR,0)
From
(select
[Custid]
,ISNULL(count(distinct Custid),0)as Count_Of_PAR
FROM
[DEV].[dbo].[Trans]
Where
complete_date >= '09/30/2012' and complete_date < dateadd(day,1,'09/30/2012')
  Category='PAR'
group by
Custid) G
Left Join
(select
IP.[Custid]
,ISNULL(count(distinct Custid),0) as Count_Of_NPAR
FROM
[DEV].[dbo].[Trans] 
Where
complete_date >= '09/30/2012' and complete_date < dateadd(day,1,'09/30/2012')
Category='NPAR'
group by
IP.[Custid])B
on G.Custid = B.Custid

Here are the problems:

1. Some times the left side of the query returns no rows. To solve that problem, I know that I can use a FULL OUTER JOIN.
2. When I use a full outer join and the results are retrieved from the right side of the outer join, the Custid value is not displayed.
Thus can you tell me what I can do so the custid value is displayed? You can change the query so the Custid  value is displayed.

Answers (1)