SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date query Help..
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tooba
Posting Yak Master

200 Posts

Posted - 11/26/2012 :  14:08:53  Show Profile  Reply with Quote
Hi Guys,

I am not getting what i want from below sql statement.

SELECT * FROM sys.dm_exec_procedure_stats
WHERE TYPE = 'P'
AND last_execution_time > = DATEDIFF(m,-1,GETDATE())

Note:- I want to see only those store procedure that execute one month from now.

I am not getting what i need. Please guide me where i am wrong.

Thank You.

jimf
Flowing Fount of Yak Knowledge

USA
2870 Posts

Posted - 11/26/2012 :  14:17:35  Show Profile  Reply with Quote
Use DATEADD!

DATEADD(m,-1,GETDATE())

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

tooba
Posting Yak Master

200 Posts

Posted - 11/26/2012 :  14:35:22  Show Profile  Reply with Quote
SELECT * FROM sys.dm_exec_procedure_stats
WHERE TYPE = 'P'
AND last_execution_time >= DATEADD(m,-1,GETDATE())

Below are result that i am getting....

last_execution_time
2012-11-26 11:31:42.183
2012-11-21 09:08:51.167
2012-11-26 11:33:08.107
2012-11-19 09:15:44.200
2012-11-26 11:32:03.273
2012-11-25 19:00:00.293
2012-11-16 12:48:15.340
2012-11-26 11:33:01.087
2012-11-16 11:39:02.753
2012-11-26 11:31:13.797
2012-11-21 15:34:19.863
2012-11-26 11:30:10.613
2012-11-20 14:55:38.713
Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/26/2012 :  15:03:28  Show Profile  Reply with Quote
That seems reasonable - all the dates are within one month of today. Isn't that what you are looking for?
Go to Top of Page

tooba
Posting Yak Master

200 Posts

Posted - 11/26/2012 :  15:21:53  Show Profile  Reply with Quote
I need data one month old...
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2870 Posts

Posted - 11/26/2012 :  15:26:46  Show Profile  Reply with Quote
All the data you have is within the last month. Do tou mean data that is exactly one month old. To help you explain yourself better, if today is 2012-11-26 15:25:40.520, do you want records for just 2012-10-26?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

tooba
Posting Yak Master

200 Posts

Posted - 11/26/2012 :  16:05:13  Show Profile  Reply with Quote
Yes you are right jimf i want (if today is 2012-11-26 15:25:40.520, do you want records for just 2012-10-26)

Thank You.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 11/27/2012 :  01:52:59  Show Profile  Reply with Quote

WHERE
CAST(last_execution_time AS DATE) = DATEADD( M, -1, CAST(getdate() AS DATE))

--
Chandu
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2870 Posts

Posted - 11/27/2012 :  06:38:59  Show Profile  Reply with Quote
WHERE last_execution_time >= dateadd(day,datediff(day,0,getdate()),0)
and last_execution_time < dateadd(day,datediff(day,-1,getdate()),0)


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000