Solved

error script track sp_configure

Posted on 2014-11-23
3
80 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 500 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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL query for highest sequence 4 61
removing unwanted rows from an sql server ranked table 13 35
SQL Server Resume 5 44
SSRS Page Header from Group Data 2 23
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

762 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