SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Days dif from Crystal formula
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jbalbo
Starting Member

10 Posts

Posted - 02/14/2013 :  16:56:46  Show Profile  Reply with Quote
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

40 Posts

Posted - 02/19/2013 :  08:40:09  Show Profile  Reply with Quote
I don't see why not.

T-SQL has IF statements. What are you stuck on?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000