Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Count in SPROC

Author  Topic 

cyberdog
Starting Member

8 Posts

Posted - 2003-02-14 : 09:06:43
I want to count(tblB.bid) records where tblA.aid = tblB.bid and get the tblA.Name. tblA.Name may exist even though there is not a associated record yet in tblB. I still want tblA.Name even if count(tblB.bid) = 0.

As example:



tblA (
aid int,
Name varchar(64)
)

tblB (
bid int,
aid int,
attributeA varchar(50),
attributeB varchar(50)
)

tblA.Name count(tblB.id)
========= ==============
Widgets 2
Dohiggies 1
Wombats 0




Every SPROC I have written returns empty.
Any thoughts on how I need to write this SPROC?

Thanks!

John



Edited by - cyberdog on 02/14/2003 09:07:47

Bambola
Posting Yak Master

103 Posts

Posted - 2003-02-14 : 09:26:21
You should use OUTER JOIN.

Bambola.

Go to Top of Page

cyberdog
Starting Member

8 Posts

Posted - 2003-02-14 : 10:52:01
Bambola,

Thanks, it worked perfectly!!

I never remember to try OUTER JOIN.

John
Go to Top of Page
   

- Advertisement -