473,395 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to select yesterdays records in sql server 2008?

omerbutt
638 512MB
hi i am writing the query to select all records for yesterday here is what i have
Expand|Select|Wrap|Line Numbers
  1. select *
  2. from ews_tiff.dbo.whatever_merged
  3. where datepart(yy,time_stamp) = datepart(yy,dateadd(m,0,getdate()))
  4. and datepart(m,time_stamp) = datepart(m,dateadd(m,0,getdate()))
  5. and DATEPART(D,time_stamp)=datepart(D,DATEADD(D,-1,GETDATE()))
  6.  
the column time_stamp is of type DATE
but when i run this query in the query analyser window it goes on debugging
any ideas , i am new to sql server
regards,

Omer Aslam
Dec 14 '10 #1
4 3552
code green
1,726 Expert 1GB
I wouldn't do it that way.
On the first of every month it will fail because the months do not match
Expand|Select|Wrap|Line Numbers
  1. datepart(m,time_stamp) = datepart(m,dateadd(m,0,getdate())) 
Another disaster looms on January 1.
Is it between midnight and midnight the previous day you require?
I might have something using BETWEEN, CAST and CONVERT
Dec 14 '10 #2
omerbutt
638 512MB
So what do you think i have'nt worked with SQL SERVER that much, if it would have been with mysql it would not be that much annoying for me ,
should i be achieving this task by targeting the last 24 hours by tracking the time
regards,
omer aslam
Dec 14 '10 #3
code green
1,726 Expert 1GB
So what do you think i have'nt worked with SQL SERVER that much, if it would have been with mysql it would not be that much annoying for me
I have no idea what you are talking about here. Why would MySQL be any easier?
should i be achieving this task by targeting the last 24 hours by tracking the time
I am confused, it is your task, which time period do you want?
Is it 'yesterday' as in 00.00.01 - 23.59.59 or the last 24 hours?
Dec 15 '10 #4
How about :

SELECT *
FROM from ews_tiff.dbo.whatever_merged
WHERE time_stamp = DATE(Now)-1

If all you need are all records dated yesterday the this should do it : DATE(Now)= today -1 = yesterday, right ?
Dec 20 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
dima69
by: dima69 | last post by:
Is it possible to select multiple records on datasheet via code ? Using SelTop and SelHeight properties dosn't give the same result as selecting the records manually, since record selectors remain...
1
by: =?Utf-8?B?S2luZXRpYyBKdW1wIEFwcGxpZmUgZm9yIC5ORVQg | last post by:
Do want to attend the Microsoft SQL Server 2008 and Visual Studio 2008 sessions at your home PC?. Yes now it is possible. Microsoft has scheduled a Webcasts for you on SQL Server 2008 and Visual...
1
by: =?Utf-8?B?bWFzYWtpeQ==?= | last post by:
Hello, I'm trying to develop 32-bit Windows Native C/C++ application using Visual Studio 2008, on 64-bit Windows Server 2008. Q1. Is it possible to develop 32-bit C/C++ application using VS 2008...
1
by: Ken Fine | last post by:
I have set up Microsoft Search Server 2008 Express. I want to know how I can query against it and return results in a form that can be bound to ASP.NET controls like ListViews. If there's simply...
1
by: Chris O'C | last post by:
See: http://blogs.zdnet.com/microsoft/?p=1519 "Microsoft officials announced at TechEd South Africa on August 6 that SQL Server 2008 has been released to manufacturing. "Microsoft officials...
1
by: =?Utf-8?B?QW50amU=?= | last post by:
I need product keys for Terminal Server Windows Server 2008 access (CALs) under MSDN - TSLM Service said they cannot provide product keys for the access.
6
by: AAaron123 | last post by:
I need to move a database from sql server 2008 to sql express 2008. Will backing up the sql server 2008 database to a file and then using that file to restore to sql express 2008 work? I don't...
2
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a server 2008 IIS 7.0 with indexing service installed. I have created the catalog and have a test page using these posts:...
1
by: BobLewiston | last post by:
I installed SQL Server 2008 Express, basic edition (SQLEXPR32_x86_ENU_Bootstrapper.exe, version 9.0.30729.1) without any problem. Then I attempted to install AdventureWorks Sample Databases for...
0
by: IT Couple | last post by:
Hi 1) Question one I'm installing SQL Server 2008 Enterprise Edition on Windowds XP (remotely) and in the 'readme' file it tells me to install SP1 first and then SQL Server 2008 but when I try to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.