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.
| 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.CntFROM ImportAlert iINNER JOIN (SELECT ImportAlertID, COUNT(*) AS CntFROM Customer GROUP BY ImportAlertID)cON c.ImportAlertID=i.ImportAlertIDNow, I have a paramater for this sproc, @typeIf @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 OptimizerTG |
 |
|
|
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 tablemThe new relation will be another table and another count.Was trying to avoid some if's but luckily only 4 @types.Zath |
 |
|
|
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 cLEFT JOIN ImportAlert AS i ON i.ImportAlertID = c.ImportAlertID AND @Type = 3[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|