Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

pull the last 3 months of data

Posted on 2011-09-12
13
Medium Priority
?
557 Views
Last Modified: 2012-05-12
Hi,
how can i pull the last 3 months of data from today's date.  I have something like this:


TimeStamp                                                 ScriptName
2010-07-26 09:16:44.000          SS_Script
2010-05-27 09:35:08.000              AE_Col
2010-02-27 09:40:07.000                                 AM_Br
0
Comment
Question by:karinos57
[X]
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
  • 7
  • 5
13 Comments
 
LVL 5

Assisted Solution

by:DavidMorrison
DavidMorrison earned 600 total points
ID: 36523324
Hi,

try this

select TimeStamp, ScriptName
from <Insert Table Name Here>
where TimeStamp between getdate() and dateadd(mm, -3, getdate())


Thanks

Dave
0
 
LVL 10

Expert Comment

by:dwe761
ID: 36523335

select * FROM [YourTable]  where TimeStamp  >= dateadd(m, -3, getdate())
0
 

Author Comment

by:karinos57
ID: 36523359
it is not returning any data even though i have data.  i want to see anything for the last 3 months.  thanks
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:dwe761
ID: 36523376
Please post your query and the data type of Timestamp field.
0
 

Author Comment

by:karinos57
ID: 36523423
the query is the same as the one u posted and the timestamp data type is datetime type.  i guess it needs to be converted into var char
0
 
LVL 10

Expert Comment

by:dwe761
ID: 36523457
No, you should not need to convert to varchar.

Did you replace what I had as [YourTable] with the actual name of your table you are querying?

Did you receive any errors?

Also, Timestamp is actually a reserved word so you may have to put it in square brackets so it knows that is your field name.  Such as :

select * FROM [YourTable]  where [TimeStamp]  >= dateadd(m, -3, getdate())
0
 

Author Comment

by:karinos57
ID: 36523534
yes, i have changed the table name.  I am not getting any error but query returns an empty table with a header only.
0
 
LVL 10

Expert Comment

by:dwe761
ID: 36523621
try this.


select top 10  [TimeStamp] ,  [ScriptName] FROM [YourTable] order by [Timestamp] desc

Please change the table name, run it, and post the results.
0
 

Author Comment

by:karinos57
ID: 36524094
here it is:
TimeStamp      ScriptName
2011-09-12 12:46:50.000      ExpressBuy
2011-09-12 12:46:40.000      SharePoint
2011-09-12 12:41:16.000      ExpressBuy
2011-09-12 12:41:14.000      SharePoint
2011-09-12 12:36:34.000      ExpressBuy
2011-09-12 12:36:28.000      SharePoint
2011-09-12 12:31:39.000      ExpressBuy
2011-09-12 12:31:20.000      SharePoint
2011-09-12 12:26:43.000      ExpressBuy
2011-09-12 12:26:37.000      SharePoint
0
 
LVL 10

Accepted Solution

by:
dwe761 earned 1400 total points
ID: 36524166
Boy, you do have a puzzling situation.
I apologize if my questions will seem obvious but I have to ask anyway because the query I gave you works fine for me.

Could you generate the script for your table and post it?
Please post the exact query you ran.

Is it possible your system date got goofed up?
Try this:
Select dateadd(m, -3, getdate()) as MyMinDate
Is it what you'd expect?

Are you sure you're looking at the correct database when you check the data type of your Timestamp field?
0
 

Author Comment

by:karinos57
ID: 36524237
this query returns a single cell like this:
2011-05-12 13:10:11.370
0
 

Author Comment

by:karinos57
ID: 36524268
i think this has done the trick:
where TimeStamp >=dateadd(month, -3, getdate())

thanks
0
 

Author Closing Comment

by:karinos57
ID: 36524275
thnx
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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