Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Days dif from Crystal formula

Author  Topic 

Jbalbo
Starting Member

10 Posts

Posted - 2013-02-14 : 16:56:46
I have the following formula from a crystal report..
Looking to see if its possible to create a daysdif in SQL ..

First part calculated which date to use as a start date depending on the criteria of the if's it decides which date to use

Second part cals which to use for the end date

Then it writes out the daysdif in days beween start and end dates

I was thinking I could come up witha daysdiff which a bunch of if's in it?

Thanks



//
Local Datevar Start;
Local Datevar End;


If (cdate({APPOINTMENT.EffDate}) <= {?date}-27 And cdate({APPOINTMENT.Expdate}) in {?date}-27 to {?date}-21)
Then Start:={?date}-28
else
if (cdate({APPOINTMENT.EffDate}) < {?date}-27 and cdate({APPOINTMENT.Expdate})> {?date}-21)
then start:={?date}-28
else
if (cdate({APPOINTMENT.EffDate}) in {?date}-27 to {?date}-21)
then
start:=cdate({APPOINTMENT.EffDate}-1) ;

// end

If ({APPOINTMENT.EffDate} <= {?date}-27 And {APPOINTMENT.Expdate} in {?date}-27 to {?date}-21)
Then
End:=cdate({APPOINTMENT.Expdate})
else
if ({APPOINTMENT.EffDate} < {?date}-27 and {APPOINTMENT.Expdate}> {?date}-21)
then
end:={?date}-21
else
if (cdate({APPOINTMENT.EffDate}) in {?date}-27 to {?date}-21 and cdate({APPOINTMENT.Expdate}) > {?date}-21)then
end:={?date}-21;

//tart:=end

Datediff("d",Start, End)



Thanks


Mar
Starting Member

47 Posts

Posted - 2013-02-19 : 08:40:09
I don't see why not.

T-SQL has IF statements. What are you stuck on?
Go to Top of Page
   

- Advertisement -