Select records based on GetDate()

Posted on 2007-12-01
Last Modified: 2010-08-05
I assume the reason why the select doesn't find any records is because it's looking at the time also?
update Top (3000) Order set CreateDate = GetDate()
where CreateDate = '2007-11-30 22:48:32.063'
select * from Order where  CreateDate = GetDate()

Open in new window

Question by:dba123
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

Accepted Solution

mdefalco earned 250 total points
ID: 20390033
Yeah, I think since the value of GetDate has changed already.

How about;
Dim strDate
strDate = GetDate()
update Top (3000) Order set CreateDate = strDate
where CreateDate = '2007-11-30 22:48:32.063'
select * from Order where  CreateDate = strDate

Open in new window

LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20390448
>I assume the reason why the select doesn't find any records is because it's looking at the time also?
yes, the second getdate() will actually return a new value, only slightly different than the update..

here is the corrected code:
SET @d = getdate()
update Top (3000) [Order] 
   set CreateDate = @d
where CreateDate = convert(datetime, '2007-11-30 22:48:32.063', 120)
   select * 
     from [Order] 
    where CreateDate = @d

Open in new window


Expert Comment

ID: 20393875
yeah, thats true. Getdate() will always provide you with instant date and time values. each instant the datetime value will be different from teh previous since the time stmp is attached with the value.

Rest you can use angelll's query. that is save the getdate() value to a variable and then try updating the table value with it and then retrieve using the same value.


Featured Post

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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