Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2006, 03:19 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Byock
Default help with SQL dates

hello,

Please help with my stored proc

I need to be able to select all books not yet return for more than 30 minutes, 2 hour and 3 hours repsectively

the following is my code....it works fine but then if my current hour is 1PM...it will display the books borrowed in 12:55 PM, which should not be shown becuase it is borrowed below or less than 30 minutes....How will i check the difference between my two dates with regards to its AM/PM?

alter procedure dbo.getBooksNotReturn
(
@search nvarchar(1024) = ''
)
Select titles, isbn, dateBorrowed, status from dbo.books
where
(@search = ''
    or (status <> 'Returned') and 1 =
   (Case
      When @search = '30m' and (datediff(hh, dateBorrowed,
          CONVERT(CHAR(20), GETDATE(), 22)) > 0.5) then
        1
      When @search = '1h' and (datediff (hh, dateBorrowed,
          CONVERT(CHAR(20), GETDATE(), 22)) > 1) then
        1
      When @search = '3h' and (datediff (hh, dateBorrowed,
          CONVERT(CHAR(20), GETDATE(), 22)) > 3) then
        1
      else
           0
   End)
)
End

 
Old March 23rd, 2006, 12:58 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to demiwolf
Default

Just curious, why are you converting the current date to CHAR? I don't have a solution but wondered if that probably has something to do with your issue.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Dates in SQL meichmann SQL Server 2000 5 April 18th, 2005 10:58 AM
SQL dates - Problem malecumbria Classic ASP Databases 4 February 16th, 2005 01:18 PM
SQL dates in American lic023 Access VBA 4 July 8th, 2004 03:06 AM
sql for searching in between given dates reshmisworld Classic ASP Databases 1 July 26th, 2003 10:23 AM
International Dates in SQL owain SQL Language 2 June 13th, 2003 03:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.