Select to view content in your preferred language

Selection Query

828
1
08-06-2012 09:06 AM
JayKappy
Frequent Contributor
I am using this SQL to run a query to find lines that are the same length (THIS WORKS BY ITSELF)

[Length] In (SELECT [Length] FROM [wMain] GROUP BY [Length] HAVING Count(*)>1 )


What I want to add to it is this  (THIS WORKS BY ITSELF)

[Material] IS NOT NULL AND [Util_ID] IS NOT NULL


I tried this but getting an error...ANYONE out there know the correct syntax?
DO I use a WHERE, if so how?

[Length] In (SELECT [Length] FROM [wMain] GROUP BY [Length] HAVING Count(*)>1 AND [Material] IS NOT NULL AND [Util_ID] IS NOT NULL)


Thanks.
Tags (2)
0 Kudos
1 Reply
SamHaycraft
Deactivated User
In SQL your GROUP BY and HAVING clauses apply only to the aggregates returned and must be the last statements.  You need to first filter out your nulls with a where clause, like so:

[Length] In (SELECT [Length] FROM [wMain] WHERE [Material] IS NOT NULL AND [Util_ID] IS NOT NULL GROUP BY [Length] HAVING Count(*)>1 AND )
0 Kudos