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 2005 Forums
 Transact-SQL (2005)
 ignore inner join

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2009-07-13 : 15:33:25

Ok, part 2 of this inner join.

I'm simplifying it again.

SELECT c.Cnt
FROM ImportAlert i
INNER JOIN (SELECT ImportAlertID, COUNT(*) AS Cnt
FROM Customer
GROUP BY ImportAlertID)c
ON c.ImportAlertID=i.ImportAlertID

Now, I have a paramater for this sproc, @type

If @type = 3 then I want the inner join, else ignore it.

Thanks again...

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-07-13 : 15:40:32
What do you mean by "ignore" the inner join?
If you ignore the inner join then c.Cnt will error out because the join defines your [c] table.

Be One with the Optimizer
TG
Go to Top of Page

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2009-07-13 : 15:43:29
Yes, after I posted the question I realized that.
May have to do some if statements in the sproc now.

Problem is, if @type = 3, there is no relation to the customer tablem
The new relation will be another table and another count.

Was trying to avoid some if's but luckily only 4 @types.

Zath
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-13 : 15:44:09
[code]SELECT c.Cnt,
i.ImportAlertID
FROM (
SELECT ImportAlertID,
COUNT(*) AS Cnt
FROM Customer
GROUP BY ImportAlertID
) AS c
LEFT JOIN ImportAlert AS i ON i.ImportAlertID = c.ImportAlertID
AND @Type = 3[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -