Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 August 7th, 2003, 12:47 PM
Authorized User
 
Join Date: Jun 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default WHERE BETWEEN search condition in sproc

Hi,

I have a stored procedure where I am trying to select items based on a date range. Input parameters from my aspx page are @startDate and @endDate, and I am selecting items from an AssignedHistory table where records have assignedDate and returnedDate fields. If an item is currently assigned, the returnedDate field is NULL; if an item has been returned and is not reassigned both the assignedDate and returnedDate fields will be populated, and if the item had been assigned, returned, and then reassigned there would be two entries (one with both fields populated representing the previous assignment and one with just assignedDate populated representing the current assignment).

I need to return all items assigned during the inputted date range. I am a little confused but I would like to do:

WHERE assignedDate BETWEEN @startDate AND @endDate
AND (here's where I am confused)

If returnedDate IS NOT NULL, where returnedDate NOT BETWEEN @startDate AND @endDate

Can someone help me with the syntax of the second part?

Thanks,

John
 
Old August 7th, 2003, 09:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
WHERE assignedDate BETWEEN @startDate AND @endDate
AND (   returnedDate IS NULL
        OR
        (returnedDate IS NOT NULL AND returnedDate NOT BETWEEN @StartDate AND @endDate)
    )
regards
David Cameron





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Condition tmadhavi SQL Server 2000 2 February 21st, 2008 03:13 AM
Problem with sproc Bob Bedell SQL Server 2005 10 January 20th, 2008 08:52 AM
NEWBIE Question: Expected "" in search condition aasiddle SQL Language 5 March 19th, 2007 03:49 PM
NEWBIE Question: Expected "" in search condition aasiddle ASP.NET 2.0 Basics 0 March 4th, 2007 11:21 AM
Help PLZ..Condition for Search Page shopgirl Classic ASP Databases 4 April 5th, 2004 10:59 PM





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