Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I am very happy with the whole site and would like to extend my compliments to all of you who work to make it one of the most useful sites (If not THE Most Useful) ...and the easiest to navigate..."

Geography

Where in the world do Tek-Tips members come from?
caddy1 (TechnicalUser)
28 Aug 09 7:09
Every time i run this function getting an error not sure what i am doing wrong.

Using Pervasive 9.71

CREATE FUNCTION WorkDays
        (IN :StartDate DATETIME, IN :EndDate DATETIME)
     RETURNS DATETIME;
 
        BEGIN
            RETURN     
               (SELECT
                 (DATEDIFF(day,:StartDate,:EndDate)+1)
                -(DATEDIFF(week,:StartDate,:EndDate)*1)
               -(CASE WHEN DATENAME(weekday,:StartDate) = 'Sunday'
                      THEN 1
                      ELSE 0
                  END)
               -(CASE WHEN DATENAME(weekday,:EndDate) = 'Sunday'
                      THEN 1
                      ELSE 0
                  END)
                  
                -(CASE WHEN DATEDIFF(day, :StartDate, :EndDate)< 7
                        THEN 1
                        ELSE 0
                   END));
                
    END
 

    #
caddy1 (TechnicalUser)
28 Aug 09 7:27
Sorry its RETURNS INTEGER; not  RETURNS DATETIME;

Still doesn't work  
mirtheil (Programmer)
28 Aug 09 9:26
And what's the error?  

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
http://www.mirtheil.com

caddy1 (TechnicalUser)
28 Aug 09 10:02
Hi

Forgot to mention the function can be created but when i try to use the function in the select statement get this message pop-up [LNA][Pervasive][ODBC Engine Interface]Expression evaluation error.

Statement  
select WorkDays('2009-01-01 00:00:00','2009-01-09 00:00:00')#
caddy1 (TechnicalUser)
1 Sep 09 10:10
Resolved my issue by removing select case   

CREATE FUNCTION WorkDays
        (IN :StartDate DATETIME, :EndDate DATETIME )
     RETURNS INTEGER;
 
 
        BEGIN
          DECLARE :Var1 Integer;
          DECLARE :Var2  Integer;       
          DECLARE :Var3  Integer;
          
          if DATENAME(weekday,:StartDate) = 'Sunday' then
          set :Var1 = 1;
          else set :Var1 = 0;
          end if;
          
          if DATENAME(weekday,:EndDate) = 'Sunday' then
          set :Var2 = 1;
          else set :Var2 = 0;
          end if;
 
          if DATEDIFF(day, :StartDate, :EndDate)< 7  then
          set :Var3 = 1;
          else set :Var3 = 0;
          end if;         
         
          
            RETURN     
               (
                (DATEDIFF(day,:StartDate,:EndDate)+1)
                 -(DATEDIFF(week,:StartDate,:EndDate)*1)
                 - :Var1
                 - :Var2
                 - :Var3
                                                 
                );
                
    END

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close