-3

Hi I am a newbie in SQL syntax.

I would like to have a query results in SQL using the below syntax.

Select * from tblSales where duedate <= todate

But when i run it was an error.

Please advise me for the correct syntax.

Thanks

Daryl
  • 35
  • 1
  • 7

3 Answers3

1

In your question the RDBMS is not mentioned..

For SQL Server your query should be

Select * from tblSales where duedate <= GETDATE()

where GETDATE() return the current system date and duedate should be a date datatype.

If you are using oracle to get current system date you can use SYSDATE

Sachu
  • 7,555
  • 7
  • 55
  • 94
  • diff between todate vs duedate = result if result <=10 then select the record – Daryl Jun 24 '15 at 01:44
  • @Daryl didn't understand what is your requirement? – Sachu Jun 24 '15 at 01:45
  • sorry i want this the result of this query select datediff(day,getdate(),Duedate )as Diff, SInumber ,InvoiceNo,Customer ,Tradedate,PaymentTerms,Duedate,Amount from tblSales where DIFF <= '10' – Daryl Jun 24 '15 at 01:53
  • @Daryl this result means can you explain with an example ..i didn't understand your first comment – Sachu Jun 24 '15 at 01:53
1
select * from(
select datediff(day,getdate(),Duedate )as Diff,
SInumber ,InvoiceNo,Customer ,Tradedate,PaymentTerms,Duedate,Amount   
from tblSales )as D where DIFF <= '10'

This is the Query i want..and it solved!

Daryl
  • 35
  • 1
  • 7
-1

You could try this:

SELECT * FROM tblSales WHERE DATE(duedate) <= CURDATE();

I don't test it yet. Hope it works