|
-
Sep 25th, 2007, 12:57 PM
#1
Thread Starter
Lively Member
[RESOLVED] SQL 2000 SELECT/Count ?
I am using SQL Server 2000. I have a field in table one that stores values, in this case 35 thru 46. I am tyring to count each of those values in table two. I can write the count statement easy enough to give me what I expect to see. EValue are the values stored in table one and count is the count of each value in table two:
EValue CountofResponse
38 65
42 4
43 1
44 6
45 18
46 20
This is what I would like to see:
EValue CountofResponse
35 0
36 0
37 0
38 65
39 0
40 0
41 0
42 4
43 1
44 6
45 18
46 20
Here is the SQL I am using now:
SELECT dbo_tblMDD.EValue, Count(dbo_tblData.Response) AS CountOfResponse
FROM dbo_tblMDD INNER JOIN dbo_tblData ON (dbo_tblMDD.EValue = dbo_tblData.Response) AND (dbo_tblMDD.VID = dbo_tblData.VID) AND (dbo_tblMDD.PID = dbo_tblData.PID)
GROUP BY dbo_tblMDD.VID, dbo_tblMDD.PID, dbo_tblMDD.EValue
HAVING (((dbo_tblMDD.VID)=47) AND ((dbo_tblMDD.PID)="340109"))
ORDER BY dbo_tblMDD.EValue;
Thanks for you help in advance!!
-
Sep 25th, 2007, 01:09 PM
#2
Re: SQL 2000 SELECT/Count ?
change your inner join to an outter join.... change your having to a WHERE and move it up to before the Group By.... change the COUNT to the following:
SUM(CASE
WHEN dbo_tblData.Response IS NOT NULL THEN 1
ELSE 0
END )
-tg
-
Sep 25th, 2007, 01:50 PM
#3
Thread Starter
Lively Member
Re: SQL 2000 SELECT/Count ?
Worked like a charm!!
Thanks techgnome
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|