Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GETDATE() in a T-SQL Job Step Command

I can't seem to get the GETDATE() syntax to work in a Job Step of type Transact-Sql Script. I put in the command as:

execute insertMostRecentUpdate 
@Data='Data', 
@Date=GETDATE()-1

But I get an "incorrect syntax near ')'" error when parsing or trying to run it. Any thoughts?

like image 661
C Bauer Avatar asked Jul 22 '10 12:07

C Bauer


People also ask

What does Getdate () function do?

The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.

What type is Getdate () SQL?

GETDATE is a nondeterministic function.

How do I query job status in SQL?

To view job activity In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance. Expand SQL Server Agent. Right-click Job Activity Monitor and click View Job Activity. In the Job Activity Monitor, you can view details about each job that is defined for this server.

How can I get Getdate?

To get the current date and time in SQL Server, use the GETDATE() function. This function returns a datetime data type; in other words, it contains both the date and the time, e.g. 2019-08-20 10:22:34 . (Note: This function doesn't take any arguments, so you don't have to put anything in the brackets.)


2 Answers

Try this:

DECLARE @date DATETIME;
SET @date = GETDATE()-1;

execute insertMostRecentUpdate 
@Data='Data', 
@Date=@date;

You cannot use GETDATE() as inline-function while calling a procedure.

like image 65
Florian Reischl Avatar answered Nov 08 '22 01:11

Florian Reischl


You could try something like this,

declare @date date
set @date = GETDATE()-1

exec insertMostRecentUpdate 'data',@date

Suprise me when i ran, thought i should compile, but I think its because you are passing a function into your proc

like image 35
Iain Avatar answered Nov 07 '22 23:11

Iain