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
Solved

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

Posted on 2013-01-22
7
352 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
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 25

Assisted Solution

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

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 400 total points
ID: 38805027
0
 

Author Comment

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

thanks!!!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
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.

792 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