all groups > sql server data mining > may 2007 >
You're in the

sql server data mining

group:

How to Disable a GROUP BY - HAVING


How to Disable a GROUP BY - HAVING LUIS
5/29/2007 4:44:14 PM
sql server data mining:
I have four tables,
1. First has Items,
2. Second has Features,
3. Third defines the ItemsFeatures
4. And temporary that sets which Items have to SELECT according Features
For this statment we do not need table(2),

IF (SELECT COUNT(*) FROM tblTemporary) = 0

SELECT A.ItemID, B.ItemDescrip FROM tblItems A ORDER BY 1

ELSE

SELECT A.ItemID, B.ItemDescrip
FROM tblItems A LEFT OUTER JOIN tblItemsFeatures B ON A.ItemID = B.ItemID
LEFT OUTER JOIN tblTemporary C ON B.FeatureID =
C.FeatureID
GROUP BY A.ItemID, B.ItemDescrip
HAVING COUNT(B.FeatureID) = (SELECT COUNT(*) FROM tblTemporary)
ORDER BY 1

If I want all Items, first SELECT is used, if I make a Features Selection,
second SELECT is executed.
QUESTION : If there a way to use ONLY ONE SELECT to do this?

Beforehand, thank you very much

--
Luis Garcia
Re: How to Disable a GROUP BY - HAVING Dejan Sarka
6/11/2007 6:55:19 PM
[quoted text, click to view]

Luis,

I would not even try to create a single statement in your case. You use IF
statement to control the flow of your procedure; in each branch, you have
your own optimized SELECT statement. In a single statement, you would
probably not be able to get the best optimization; also, I like procedures
where I can follow the flow.

--
Dejan Sarka
http://blogs.solidq.com/EN/dsarka/

AddThis Social Bookmark Button