Solved

How do I resolve the following error using SQL Server 2008 "Invalid parameter 1 specified for datediff"?

Posted on 2016-09-23
1
45 Views
Last Modified: 2016-09-23
How do I resolve the following error using SQL Server 2008?

dtCreated has a data type of datetime and has a value such as "2009-08-03 00:00:00.000"

Msg 1023, Level 15, State 1, Procedure proc_CSL_UnresolvedRequests, Line 3
Invalid parameter 1 specified for datediff.
Msg 1023, Level 15, State 1, Procedure proc_CSL_UnresolvedRequests, Line 5
Invalid parameter 1 specified for datediff.
Msg 1023, Level 15, State 1, Procedure proc_CSL_UnresolvedRequests, Line 7
Invalid parameter 1 specified for datediff.

USE [CSL]
GO
/****** Object:  StoredProcedure [dbo].[proc_CSL_DistinctEntity]    Script Date: 09/23/2016 17:42:33 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[proc_CSL_UnresolvedRequests]
AS
SELECT revID,dtCreated, 'ReversePositive', createdBy, datediff("d", dtcreated,getdate())
FROM tbl_CSL_Reversepositive where _status='Not Completed'
UNION SELECT stopID, dtCreated,'StopPayment/VoidCheck',createdBy, datediff("d", dtcreated,getdate())
FROM tbl_CSL_Stopvoidpay where _status='Not Completed'
UNION SELECT undeliverID, dtCreated, 'UndeliverableChecks',createdBy, datediff("d", dtcreated,getdate())
FROM tbl_CSL_Undeliverablechecks where _status='Not Completed'
0
Comment
Question by:zimmer9
1 Comment
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41813288
Msg 1023, Level 15, State 1, Procedure proc_CSL_UnresolvedRequests, Line 3
Invalid parameter 1 specified for datediff.
Msg 1023, Level 15, State 1, Procedure proc_CSL_UnresolvedRequests, Line 5
Invalid parameter 1 specified for datediff.
Msg 1023, Level 15, State 1, Procedure proc_CSL_UnresolvedRequests, Line 7
Invalid parameter 1 specified for datediff.
check the DateDiff syntax here:

DATEDIFF (Transact-SQL)
https://msdn.microsoft.com/en-us/library/ms189794.aspx

hence, you need to replace:
datediff("d", dtcreated,getdate())

Open in new window

to:
datediff(day, dtcreated,getdate())

Open in new window

instead
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

706 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

20 Experts available now in Live!

Get 1:1 Help Now