Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Select records based on GetDate()

Posted on 2007-12-01
3
Medium Priority
?
171 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 1000 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 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:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

927 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