Quote:
Originally Posted by ck9663
Use parenthesis to group your conditions
-
-
WHERE ([Title] LIKE '%delete%'
-
OR [Comment] LIKE '%test%'
-
OR [Title] LIKE '%test%'
-
OR [Comment] LIKE '%delete%'
-
OR [OnlineVersionsSize] = 0)
-
AND [CreatedByUser] IN (
-
SELECT [CreatedByUser]
-
FROM [DMSDB].[dbo].[KDOCUMENT]
-
GROUP BY [CreatedByUser]
-
HAVING COUNT([CreatedByUser]) > 20)
-
-
Conditions are evaluated left to right. If one of those ORs is true, your whole condition is true.
Similar to math formula:
2 + 3 * 5 = 25
2 + (3 * 5) = 17
Happy coding!
-- CK
Wow, thank you!
It works like a charm, and the best part is that I was not completely off, it was just some paranthesis missing.
I now just discovered one thing you might be able to help me with:
This query: SELECT [CreatedByUser]
FROM [DMSDB].[dbo].[KDOCUMENT]
GROUP BY [CreatedByUser]
HAVING COUNT([CreatedByUser]) > 20)
counts ALL users in the entire table, but I only want it to count the ones with the criteria listed in the first query (Title and Comment equals "test" and/or "delete". When I try to put:
WHERE ([Title] LIKE '%delete%'
OR [Comment] LIKE '%test%'
OR [Title] LIKE '%test%'
OR [Comment] LIKE '%delete%'
OR [OnlineVersionsSize] = 0
into the second query like this:
SELECT [DocID], [Title],[CreatedByUser], [CreateDate], [LastModifiedByUserName], [LastModificationDate], [Comment], [OnlineVersionsSize]
FROM [DMSDB].[dbo].[KDOCUMENT]
WHERE [CreatedByUser] IN (
SELECT [CreatedByUser]
FROM [DMSDB].[dbo].[KDOCUMENT]
WHERE ([Title] LIKE '%delete%'
OR [Comment] LIKE '%test%'
OR [Title] LIKE '%test%'
OR [Comment] LIKE '%delete%'
OR [OnlineVersionsSize] = 0)
GROUP BY [CreatedByUser]
HAVING COUNT([CreatedByUser]) > 20)
it shows 0 results. Any ideas?
There might be another way to do this, so I am very open for suggestions :)