Solved

error script track sp_configure

Posted on 2014-11-23
3
81 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
[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
  • 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

734 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