Solved

Select records based on GetDate()

Posted on 2007-12-01
3
165 Views
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

0
Comment
Question by:dba123
3 Comments
 
LVL 4

Accepted Solution

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

0
 
LVL 142

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:
DELCARE @d DATETIME 
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

0
 
LVL 5

Expert Comment

by:ursangel
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.

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
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 …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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