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.
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 dateThen it writes out the daysdif in days beween start and end datesI 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}-28elseif (cdate({APPOINTMENT.EffDate}) < {?date}-27 and cdate({APPOINTMENT.Expdate})> {?date}-21)then start:={?date}-28elseif (cdate({APPOINTMENT.EffDate}) in {?date}-27 to {?date}-21)thenstart:=cdate({APPOINTMENT.EffDate}-1) ;// endIf ({APPOINTMENT.EffDate} <= {?date}-27 And {APPOINTMENT.Expdate} in {?date}-27 to {?date}-21)ThenEnd:=cdate({APPOINTMENT.Expdate})elseif ({APPOINTMENT.EffDate} < {?date}-27 and {APPOINTMENT.Expdate}> {?date}-21)thenend:={?date}-21elseif (cdate({APPOINTMENT.EffDate}) in {?date}-27 to {?date}-21 and cdate({APPOINTMENT.Expdate}) > {?date}-21)thenend:={?date}-21;//tart:=endDatediff("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? |
|
|
|
|
|