Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

error script track sp_configure

Posted on 2014-11-23
3
Medium Priority
?
84 Views
Last Modified: 2014-12-08
Hello,

The error Incorrect syntax near '>'. is returned when I executed
 SELECT @LastUpdateTime = DATEADD (HOUR, @hours, @LastUpdateTime);
 SELECT @LastUpdateTime = DATEADD (MINUTE, @minutes, @LastUpdateTime);
 SELECT @LastUpdateTime = DATEADD (SECOND, @seconds, @LastUpdateTime);
 SELECT @LastUpdateTime = DATEADD (MILLISECOND, @milliseconds, @LastUpdateTime); 

SELECT @LastUpdateTime AS 'sp_configure options last updated'; 

IF EXISTS 
(select @LastUpdateTime > DATEADD(DAY, -1, GETDATE()))

BEGIN 
RAISERROR('Error 1, level 11', 11, 1)
    RETURN
END

Open in new window


How can I resolve?

Thanks

Regards
0
Comment
Question by:bibi92
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Koen Van Wielink
ID: 40461245
Not sure what your query is trying to do, but the error is throws because you can't put comparison operators in the select part of the query. They have to be in a where clause.
Try this:

IF EXISTS 
(select 1
where	@LastUpdateTime > DATEADD(DAY, -1, GETDATE()))

Open in new window

0
 

Author Comment

by:bibi92
ID: 40461479
Ok, the syntax error is resolved but the raiserrror doesn't work.

Thanks
0
 
LVL 13

Accepted Solution

by:
Koen Van Wielink earned 2000 total points
ID: 40461519
What is it you're trying to achieve? This is from the Technet:

A RAISERROR severity of 11 to 19 executed in the TRY block of a TRY…CATCH construct causes control to transfer to the associated CATCH block.

Since you're raising an error with severity 11, you should probably put it inside a try...catch construct.

SELECT @LastUpdateTime = DATEADD (HOUR, @hours, @LastUpdateTime);
 SELECT @LastUpdateTime = DATEADD (MINUTE, @minutes, @LastUpdateTime);
 SELECT @LastUpdateTime = DATEADD (SECOND, @seconds, @LastUpdateTime);
 SELECT @LastUpdateTime = DATEADD (MILLISECOND, @milliseconds, @LastUpdateTime); 

SELECT @LastUpdateTime AS 'sp_configure options last updated'; 

BEGIN TRY

IF EXISTS (	select	1
			where	@LastUpdateTime > DATEADD(DAY, -1, GETDATE()))
	Begin
	RAISERROR('Error 1,	level 11', 11, 1)
	End

END TRY

BEGIN CATCH

	DECLARE @ErrorMessage NVARCHAR(4000);
    DECLARE @ErrorSeverity INT;
    DECLARE @ErrorState INT;

    SELECT @ErrorMessage = ERROR_MESSAGE(),
           @ErrorSeverity = ERROR_SEVERITY(),
           @ErrorState = ERROR_STATE();

    -- Use RAISERROR inside the CATCH block to return 
    -- error information about the original error that 
    -- caused execution to jump to the CATCH block.
    RAISERROR (@ErrorMessage, -- Message text.
               @ErrorSeverity, -- Severity.
               @ErrorState -- State.
               )
END CATCH

Open in new window


You can replace the code in the catch block with your own error handling code if you like.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

885 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