Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-22
7
Medium Priority
?
366 Views
Last Modified: 2013-01-22
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
Comment
Question by:aatjan
[X]
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
7 Comments
 
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
0
 
LVL 25

Expert Comment

by:jogos
ID: 38804610
GetDate() returns also the time
0
 

Author Comment

by:aatjan
ID: 38804908
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Assisted Solution

by:jogos
jogos earned 400 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

0
 

Author Comment

by:aatjan
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?

thanks!
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1600 total points
ID: 38805027
0
 

Author Comment

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

thanks!!!
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard 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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 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