I have a crossjoin between two tables where I need the PayrollOID for a set of conditions. I have tried doing this in a CASE statement, CASE and IIF statements in the WHERE clause, now in the regular code realizing I will have to do another pass to get rid of empties.
I have Job Approvals that go to payroll based on the date of approval. We are changing that to the date the approval is entered.
If the Apr_Entered is >= JobPayStart and Apr_Entered <= TimesheetsDue and JobEndDate >= JobPayStart and JobEndDate <=JobPayEnd - give me that OID. Don't look for anything else.
Else - I want the job to be paid where the Apr_Entered is >= JobPayStart and Apr_Entered <= JobPayEnd.
I am getting an error: Error in list of function arguments: '>' not recognized. Unable to parse query text.
But it does run. I am however getting duplicates where both brackets are being shown for an overlap job.
I need help tightening my bookends up - so when first is found get out. I also need to know why I am still getting the error when I have converted datetime fields to Date for comparison.
IIF(CONVERT(varchar(10), ProtoPayroll.AprEntered,110) >= CONVERT(varchar(10), PayDates.PayStartDate,110)
AND CONVERT(varchar(10), ProtoPayroll.AprEntered,110) <= CONVERT(varchar(10), PayDates.TimesheetsDue,110)
AND CONVERT(varchar(10), ProtoPayroll.JobEndDate,110) >= CONVERT(varchar(10), PayDates.PayStartDate,110)
AND CONVERT(varchar(10), ProtoPayroll.JobEndDate,110) <= CONVERT(varchar(10), PayDates.PayEndDate,110),
--First IIF's result
CONVERT(nvarchar(40), dbo.Paydates.OID),
--Now another IIF
IIF (CONVERT(varchar(10), ProtoPayroll.AprEntered,110) >= CONVERT(varchar(10), PayDates.PayStartDate,110)
AND CONVERT(varchar(10), ProtoPayroll.AprEntered,110) <= CONVERT(varchar(10), PayDates.PayEndDate,110),
--Second IIF's results
CONVERT(nvarchar(40), dbo.Paydates.OID), SPACE(40))) AS PayrollOID