Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2008, 10:16 AM
Authorized User
 
Join Date: Sep 2007
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB WHERE clause for Recent Values

I have a database containing a number of events for my Walking Group website. I have a History page where I would like to show details of the four most recent (past) events. I have a field in the database called "Start Date". I want to select those records whose "Start Date" is before today's date, and only a maximum of four records. I plan to display the results in descending order (i.e. most recent first) using a Datalist control.

I have set up a data source and am trying to configure it using the Wizard. I can create a simplified WHERE condition using the EventID field (an integer) to display some records, e.g. WHERE([EventID]>=6). This displays the four most recent walks, but only because the records were originally entered in ascending date sequence.

Do I have to define a Query that arranges the records in "Start Date" order and then somehow pick out the first few records, using the Query in the WHERE clause?

I am using VWD 2005 Express Edition with SQL Server Express (but my data source is an Access database).

Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express
__________________
Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express
 
Old February 21st, 2008, 10:27 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can use a query such as this:

SELECT
  Top 4 *
FROM Table
WHERE [date] < getdate()
order by [date] desc

It has been a long time since i have used access but i think you might need to replace getdate() with Now() so that access returns the current date.

In any event that should work for you.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 21st, 2008, 01:11 PM
Authorized User
 
Join Date: Sep 2007
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:SELECT
  Top 4 *
FROM Table
WHERE [date] < getdate()
order by [date] desc
Thanks, Doug. As soon as I saw your post I thought "I should have remembered that syntax" from my Access training! I tried substituting Now() in Access and in VWD and it's great.

Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express





Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple values in "IN" clause - Please help! billkrieger ASP.NET 1.0 and 1.1 Professional 5 October 22nd, 2007 05:23 PM
Most recent list bmains Forum and Wrox.com Feedback 3 June 29th, 2004 07:38 AM
AS Clause on Functions VB.Net Duncan VS.NET 2002/2003 1 May 1st, 2004 08:38 AM
Most recent ID Colonel Angus SQL Server 2000 6 March 31st, 2004 09:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.