Solved

error script track sp_configure

Posted on 2014-11-23
3
72 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 12

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 12

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MSSQL 2014 Query Synthax 8 38
SQL JOIN 6 39
SQL JOIN + SUBQUERY? 3 14
Merge Statement 3 0
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…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now