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?
The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.
GETDATE is a nondeterministic function.
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.
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.)
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With