Solved

Select records based on GetDate()

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.​
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now