Hi Everyone,

Can you tell me how to fix my query so I can determine if an amount entered into a textbox is < the largest number in a database table?

Here is some sample data:


If the user enters 35 I'm looking for the query to indicate that this number 35 is < the largest number which happens to be 50.

Here is the query I tried to use:

strSqlStatement =
                "Select 1 " & _
                  "From Categories " & _
                 "Where @CategoryNumber < Max(CategoryNumber) "

I get this error when running it so I know my query is wrong:

An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

Can you show me how to do this query so it will work?



If you need to retrieve the largest value from the table, doing a

SELECT MAX(CategoryNumber) FROM Categories

will return the expected value, that can be read using a data reader into an (i.e.) integer

The the result from the query can then be compared with the value entered on the text box converted to (i.e.) integer.

Hope this helps

This question has already been answered. Start a new discussion instead.