This will return the first non-null value in the brackets and can take more than two arguments if required. What is your dateadd logic trying to achieve?
Most of the logic you placed in there only works with Crystal and not T-SQL. I’m trying to convert it into SQL Server logic. The dateadd logic needs to be used in instances where it’s Null, it will bring in a full day which will be used in the logic to calculate the date difference, that’s a seperate piece of logic which I was able to translate.
OK, let’s wind back to the start of the requirement then.
What field(s) do you have and what do you want to achieve in terms of data - for example, if End Date is null, show nulls else apply a calculation to it that does a difference in hours, etc.
@indy - figured this out - cdatetime is a convert to date/time function in Crystal Reports.
So it looks like you want to add 1 second short of two days to the date part of the datetimefieldstart if it is null. Your overall logic would therefore be:
COALESCE(datetimefieldend, (DATEADD(SECOND, 172799 ,CAST(CAST(datetimefieldstart AS DATE) AS DATETIME)))
The 172799 is 1 second short of two days. The double cast is needed to first strip the time off then convert back to datetime to support the addition of the seconds. If you only wanted the same day just before midnight, use 86399 instead.