date parameters in readerrorlog proc

from the syntax in http://www.mssqltips.com/sqlservertip/1476/reading-the-sql-server-log-files-using-tsql/, i tried the below...

EXEC master.dbo.xp_readerrorlog 1, 1, 'Starting', 'up', GETDATE()-1, GETDATE() , 'asc'

but it is giving error.. Incorrect syntax near ')'.

can you please run the above and see  what may be wrong?

thanks.
LVL 5
25112Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Wild guesses:
*  Use DATEADD(d, -1, GETDATE()) instead of GETDATE() - 1
*  The link shows that xp_readerrorlog has four parameters, and the call in this question has seven.
0
COANetworkCommented:
declare @d1 datetime, @d2 datetime
select @d1 = getdate()-1, @d2 = getdate()
EXEC master.dbo.xp_readerrorlog 1, 1, 'Starting', 'up', @d1, @d2, 'asc' 

Open in new window

GETDATE() is a nondeterministic function (it's return value changes every time it's called), so it is tricky using it as input parameter to a stored proc.  assignment to a variable works best.  You may also be able to get it to work if you explicitly specify parameter names on the procedure call, but I am not 100% sure of that.  try it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve WalesSenior Database AdministratorCommented:
Haven't been able to make it work while passing in a parameter like this.

This question was asked and answered here:
http://www.sqlservercentral.com/Forums/Topic1289572-146-1.aspx

A work around that would seem to give you what you are looking for is included there.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

25112Author Commented:
it worked, thanks..

jimhorn, dateadd did not make a difference for me.. thanks for trying.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
sjwales - Can you post the relevant content of the link into this question?  Reason I ask is that EE is cracking down on what they refer to as 'blind links', and if that link goes bad, we have an answer with no content other than 'go here' with a bad link.  Thanks in advance.
0
Steve WalesSenior Database AdministratorCommented:
Code from aforementioned link:

This code will read your archived error logs into a temporary table that can then be queried for later research.  If you keep more than 5 old error logs (maybe you cycle weekly and keep for 8 weeks) then the readerrorlog would need to be replicated for up to 8 old logs instead of 5.

You can then query the table you load to your heart's content and of course, when done, clean up after yourself and drop any temp tables created.

/* =================================================================================================================== */
/* Load SQL Error Logs to a temp table for research


Whole script at:
http://www.sqlservercentral.com/scripts/Error+Logging/70611/
*/


CREATE TABLE #SQLErrorLog
(
LogDate DATETIME,
ProcessInfo VARCHAR(20),
Text VARCHAR(1900)
)
GO

INSERT INTO #SQLErrorLog
EXEC xp_readerrorlog 0
go
INSERT INTO #SQLErrorLog
EXEC xp_readerrorlog 1
go
INSERT INTO #SQLErrorLog
EXEC xp_readerrorlog 2
go
INSERT INTO #SQLErrorLog
EXEC xp_readerrorlog 3
go
INSERT INTO #SQLErrorLog
EXEC xp_readerrorlog 4
go
INSERT INTO #SQLErrorLog
EXEC xp_readerrorlog 5
go

SELECT * FROM #SQLErrorLog
WHERE Text LIKE '%fail%' OR Text LIKE '%error%'
ORDER BY LogDate DESC

SELECT * FROM #SQLErrorLog
WHERE LogDate >= CONVERT(datetime,'05/04/2012') AND LogDate < CONVERT(datetime,'05/16/2012')
ORDER BY LogDate DESC

DROP TABLE #SQLErrorLog

Open in new window

0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.