Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GETDATE() causing syntax error in SQL Server 2008

I just created a stored procedure to insert data into a table after performing some calculations. My create procedure code is below:

ALTER PROCEDURE [dbo].[myStoredProc] 
    @log_id INT,
    @job_nm VARCHAR(20),
    @feed_in_out_ind CHAR(1) = null,
    @process_dt DATETIME = null,
    @procedure_dt DATETIME = NULL,  
    @procedure_nm VARCHAR(20),
    @object_ty VARCHAR(20),
    @operation_ty VARCHAR(20),
    @num_records INT,
    @success_status BIT,
    @error_msg VARCHAR(50) = NULL,
    @start_time DATETIME,
    @end_time DATETIME = null
AS    

When I try to call the stored proc, if I use the GETDATE() for any of the datetimes, I get a syntax error Incorrect syntax near ')' When I replace the GETDATE() with an actual datetime, the procedure runs correctly.

Here is my calling code:

EXEC myStoredProc 
    @log_id = 1, 
    @job_nm = 'It',
    @feed_in_out_ind = 'i',
    @process_dt = GETDATE(),
    @procedure_dt = GETDATE(),
    @procedure_nm = 'Test 1', 
    @object_ty = 'test',
    @operation_ty = 'test',  
    @num_records = 50, 
    @success_status = 0, 
    @error_msg = 'Hello',
    @start_time = GETDATE(),
    @end_time = GETDATE()

Any ideas? Thanks.

like image 537
chama Avatar asked Apr 17 '26 02:04

chama


1 Answers

Try

DECLARE @Now AS DATETIME
SET @Now = GETDATE()

EXEC myStoredProc 
    @log_id = 1, 
    @job_nm = 'It',
    @feed_in_out_ind = 'i',
    @process_dt = @Now ,
    @procedure_dt = @Now ,
    @procedure_nm = 'Test 1', 
    @object_ty = 'test',
    @operation_ty = 'test',  
    @num_records = 50, 
    @success_status = 0, 
    @error_msg = 'Hello',
    @start_time = @Now ,
    @end_time = @Now 
like image 149
Carson Avatar answered Apr 19 '26 15:04

Carson