date comparison

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I'm trying to filter rows to a datetime column as it matches to a datetime
column in another table. For example:
For Each irow In dsbnlsum.Tables(0).Select("inv_dt between '" &
(irowd("inv_dt") - 1) & Chr(39) & " and '" & (irowd("inv_dt") + 1) &
Chr(39))

(Developed in vb .net, but a basic question for sql server as well.)

Note that I took a datetime column in a table represented by irowd and
overlapped it, so that my datetime column (inv_dt) would be inside the
range. I'm not even sure this will work, but is there a better way? FYI -
inv_dt is often created as Now, so it could be 8/22/2002 5:16pm or
03/18/2001 12:02am, etc.

Tx for any help.

Bernie Yaeger
 
WIth T-SQL, you can use a between. Here is a Query Analyzer Script:

DECLARE @StartDate datetime
DECLARE @EndDate datetime

SET @StartDate = '3/18/2001 12:02 AM'
SET @EndDate = '8/22/2002 5:16 PM'

SELECT * FROM MythicalTable
WHERE MythDate BETWEEN @StartDate AND @EndDate

I would filter in the database rather than with a DataView, as you can end
up with lots of records that simply get thrown out.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top