I have some App using Visual studio 2008 and C#. some small App that im working on during my college study. (still student) I need to show in datagridview all the results (the App deals with cars rent) for Available cars between 2 dates. In the DB i have table call "orders" in this table there is rows with order for cars and the dates the car is rented. ineed to show in the results all the cars that dont hold this dates or between them..... i know what to write to select the dates ("SELECT * FROM orders WHERE (fromDate != @p1) AND (toDate != @p2)) but what to write if not between the dates?

Recommended Answers

All 4 Replies

Use NOT BETWEEN @p1 and @p2.

commented: That is what I would do +14

Please help!!!! something like that? ("SELECT * FROM orders WHERE (fromDate != @p1) AND (toDate != @p2) AND NOT BETWEEN @p1 AND @p2")????

Why are you comparing to make sure it isn't equal to the fromDate and toDate? Also is this MSSQL?

Declare @StartDate DateTime, @EndDate DateTime
Set @StartDate = Cast('1/1/2009' as DateTime)
Set @EndDate = Cast('1/1/2010' as DateTime)

Select *
From Invoice
Where OrderDate >= @StartDate and OrderDate < @EndDate

--or

Select *
From Invoice
Where OrderDate BETWEEN @StartDate and @EndDate

I was try this code and it look like its working..... it can be?

"SELECT * FROM orders WHERE (fromDate NOT BETWEEN @p1 AND @p2) AND (toDate NOT BETWEEN @p1 AND @p2)"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.