Frage

I was trying to do a 'Latest Products' page for an eShop project I'm working on. Basically, I want to show a number of products, say 10, from a table in my db that where added in my database in the last 30 days or less.

First I tried to use the GridView function in VB.NET, where it auto-populates the table but can't be limited and then I tried this SQL statement, which isn't working, giving me an error.

SELECT *
FROM Product
WHERE DateAdded > (SELECT DATEADD(d,-30,(SELCT MAX(DateAdded) FROM Product)) AS "Last 30 Products Added");
ORDER BY DateAdded DESC

My database has a table called 'Product' which has various columns:

  • ProductID
  • CategoryID
  • ProductModelNo
  • ProductImage
  • ProductName
  • UnitName
  • ProductActive
  • DateAdded

Any idea on how I can solve the problem ?

War es hilfreich?

Lösung

You are looking for the DATEDIFF function to compare the DateAdded with NOW().

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top