Comparing Date in SQL Server 2000

Posted on 2007-07-31
Last Modified: 2010-03-20
Hi experts,

I have a problem with SQL Server 2000

I have a table Date :
                                          ID                      int 4                NOT NULL
                                          FromDate         datetime 8       ALLOWS NULL
                                         ToDate              datetime 8       ALLOWS NULL

and I want to create a Store Procedure "spCheckDate"  :

         + Input : @InputDate
         + Output : return 1 if FromDate <= @InputDate <= ToDate , else return 0
Date table has many rows and I want to check @InputDate with all rows by a store procedure
Can everyone help me ? Thanks !!!!
Question by:trung85gn
    LVL 75

    Accepted Solution

    Hello trung85gn,

    CREATE PROC spCheckDate
    @ImputDate datetime

       IF EXISTS (SELECT 1 FROm [Date] WHERE @inputDate BETWEEN FromDate AND ToDate)
      ELSE RETURN(0)

    Aneesh R

    Author Comment

    Thanks !
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    Thanks for the Grade toooooo :)
    I think you need to look in the User guide regading the Grading

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now