Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

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

Hi,

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
      
      
AS
BEGIN
SET Dateformat YMD
if @DT_Requested >= GETdate() and @Firsttime <= @Lasttime

    SELECT '1' AS IsValid
ELSE
    SELECT '0' AS IsValid
END

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!
0
aatjan
Asked:
aatjan
  • 3
  • 2
  • 2
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
0
 
jogosCommented:
GetDate() returns also the time
0
 
aatjanAuthor Commented:
Hi,

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 ....

thanks!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jogosCommented:
Do this query to know what you are comparing with

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

Open in new window

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

thanks!
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
aatjanAuthor Commented:
@AngelIII: found it and it works.

thanks!!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now