0

We have been working on this query for a while and can't understand what the error means that we are getting. The error is "The datediff function requires 3 argument(s)"

SELECT 
a.nihrm__BookingContact__c as BOOKING_CONTACT, 
a.Name as ACCOUNT_NAME, 
b.Email as EMAIL, 
b.FirstName as FIRST_NAME, 
b.LastName as LAST_NAME, 
c.FirstName as BOOKING_OWNER_FIRST_NAME, 
c.LastName as BOOKING_OWNER_LAST_NAME 
FROM nihrm__Booking__c_Salesforce a 
JOIN Contact_Salesforce b 
ON a.Id = b.Id 
JOIN User_Salesforce c 
ON a.Id = c.Id 
WHERE a.nihrm__BookingStatus__c = 'Definite' 
AND a.nihrm__BookingTypeName__c = 'Group'
AND a.nihrm__DepartureDate__c >= dateadd(day,datediff(day,1,GETDATE(),0)) 
AND a.Id NOT IN (SELECT Id FROM nihrm__Booking__c_Salesforce WHERE Date > dateadd(day,datediff(day,1,GETDATE(),0)))

Any help or guidance would be greatly appreciated!

1

1 Answer 1

1

I think you have a misplaced closing parenthesis

If you break out your NOT IN statement, it looks like:

SELECT Id 
FROM nihrm__Booking__c_Salesforce 
WHERE Date > 
dateadd(
    day,
    datediff(
        day,
        1,
        GETDATE(),
        0
    )
)

Which makes datediff have 4 parameters and dateadd have 2.

Should likely instead be:

SELECT Id 
FROM nihrm__Booking__c_Salesforce 
WHERE Date > dateadd(
    day,
    datediff(
        day,
        1,
        GETDATE()
    ),
    0
    )
)

With the closing datediff parenthesis before the 0.

Not the answer you're looking for? Browse other questions tagged or ask your own question.