Quantcast
Viewing latest article 9
Browse Latest Browse All 30

how to include max in sql where clause?

how to include max in sql where clause?

Asked By: Zulu Z
Originally Asked On: 2014-01-06 02:01:00
Asked Via: stackoverflow

I have to create a query to return a next installment date and have a problem with condition when there is a record with no next date (e.g. already paid) but I still need to return that record. Installments payments are every 30 days. Like that:

SELECT u.idloan, t.instdate 
FROM   loans u, schedule t 
WHERE  t.instdate IS NOT NULL
AND    (t.instdate > CONVERT(VARCHAR,getdate(),102) 
AND    t.instdate < DateAdd(DAY, 30, GetDate()) 
AND    t.loanid= u.idloan
ORDER BY u.idloan

With query above I get the loan next payment date but but no records with loans already paid. I was thinking about adding:

or max (t.instdate) <  convert(varchar,getdate(),102)

But getting error cannot include max in where clause.
Any work around? Working on SQL Server 2012.

Thanks.

He received 1 answers
without selecting any answers.

If the selected answer did not help you out, the other answers might!

All Answers For: how to include max in sql where clause?

xdazz’s answer to

how to include max in sql where clause?

Using the HAVING clause:

HAVING  max(t.instdate) <  convert(varchar,getdate(),102)

Of course, you should really check out the original question.

The post how to include max in sql where clause? appeared first on Tech ABC to XYZ.


Viewing latest article 9
Browse Latest Browse All 30

Trending Articles