sql server query to determine if requested date and time are OK

Posted on 2013-01-22
Last Modified: 2013-01-22

I have a query which does not works:-

ALTER PROCEDURE [dbo].[stp_validate_DT_Requested]
      -- Add the parameters for the stored procedure here
      @DT_Requested as Date,
@Firsttime as Time,
 @Lasttime as Time
SET Dateformat YMD
if @DT_Requested >= GETdate() and @Firsttime <= @Lasttime

    SELECT '1' AS IsValid
    SELECT '0' AS IsValid

What i expect that it will do is to check if a requested date is bigger or the same as the current date and that the requested endtime is later then the start time. An agenda check.

What is wrong?
thanks for your help!
Question by:aatjan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38804514
I see nothing "wrong" ...
please clarify how you call the procedure, and what you get as output, and what you expect as output.
maybe you get an error?
please clarify
LVL 25

Expert Comment

ID: 38804610
GetDate() returns also the time

Author Comment

ID: 38804908

This is what i'm entering when executing the query from studio:-

EXEC      @return_value = [dbo].[stp_validate_DT_Requested]
            @DT_Requested = '2013/01/22',
            @Firsttime = '09:00',
            @Lasttime = '10:00'

SELECT      'Return Value' = @return_value

I think that the return value should be a 1, because dtrequested is the current date.
and the lasttime is bigger then the first time ....

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

LVL 25

Assisted Solution

jogos earned 100 total points
ID: 38804999
Do this query to know what you are comparing with

select getdate(),CONVERT(datetime,'2013/01/22')

Open in new window


Author Comment

ID: 38805022
ok, so that is the reason why mydate is smaller ....
now we must get rid of the timepart of getdate. How to do that?

LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 400 total points
ID: 38805027

Author Comment

ID: 38805146
@AngelIII: found it and it works.


Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server maintenance plan 8 64
Using this function 4 54
Can a Trigger trigger a Trigger? 4 47
What is GIS method of Geometry data type? 6 36
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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