Page 2 of 2 FirstFirst 12
Results 41 to 47 of 47

Thread: Database application query problem

  1. #41

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    39

    Re: Database application query problem

    Thanks for your reply and for the links, This is my current code:
    Code:
        rs1.Open "CL1", ds1, adOpenDynamic, adLockOptimistic
        que = "SELECT DateDiff('h',0,Sum(end_time-call_in)) &  Format(Sum(end_time-call_in), ':nn:ss') as TotalTime "
        que = que + "From CL1 WHERE call_in Between #" + Trim(Text1.Text) + "# and #" + Trim(Text2.Text) + "#"
        que = que & " AND Format(call_in,'w') NOT IN(1,7) "
        que = que & " AND Int(call_in) NOT IN"
        
        If (List1.ListCount = 1) Then
        que = que & "(" & Int(CDate(List1.List(iloop))) & ") "
        Else
        For iloop = 0 To List1.ListCount - 1
        TempArray() = Split(List1.List(iloop), "/")
        MyDate = DateSerial(TempArray(2), TempArray(0), TempArray(1))
    
         If (iloop = List1.ListCount - 1) Then
        que = que & " " & Int(MyDate) & ") "
        Else
        If (iloop > 0) Then
        que = que & " " & Int(MyDate) & ", "
        Else
        que = que & " (" & Int(MyDate) & ", "
        End If
        End If
        
        Next iloop
        End If
        que = que & " AND end_time Is Not Null;"
        Set rs1 = ds1.Execute(que)
        MSFlexGrid1.TextMatrix(1, 5) = rs1("TotalTime").Value
        Text4.Text = que
    The query now has no errors but the outcome is the same as the result of excluding weekends(the section for excluding dates is not effective even though it looks correct). Dunno where is it wrong?
    The query on running looks like:
    SELECT DateDiff('h',0,Sum(end_time-call_in)) & Format(Sum(end_time-call_in), ':nn:ss') as TotalTime From CL1 WHERE call_in Between #08/01/2008# and #08/31/2008# AND Format(call_in,'w') NOT IN(1,7) AND Int(call_in) NOT IN (8/28/2008, 8/29/2008, 8/22/2008, 8/21/2008) AND end_time Is Not Null;
    Thanks
    Last edited by cool11; Sep 8th, 2008 at 03:27 PM.

  2. #42

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    39

    Re: Database application query problem

    Hi got the solution, the #'s were missing for the dates,now its working fine .
    Is the loop proper or am i making it too complicated?

    Thanks so much

  3. #43
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Database application query problem

    It don't see how the code you posted could have created the query you showed - there is nothing which could output values like 8/28/2008, it should just be numbers like 34523 instead.

    There are lots of If's in your code that aren't needed, as well as the dreaded CDate. Here is how I would do the same thing:
    Code:
    ...
        que = que & " AND Int(call_in) NOT IN ("
        
        For iloop = 0 To List1.ListCount - 1
          TempArray() = Split(List1.List(iloop), "/")
          MyDate = DateSerial(TempArray(2), TempArray(0), TempArray(1))
          If (iloop = List1.ListCount - 1) Then
            que = que & Int(MyDate)
          Else
            que = que & Int(MyDate) & ", "
          End If
        Next iloop
    
        que = que & ") AND end_time Is Not Null;"
    ...

  4. #44

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    39

    Re: Database application query problem

    Hi Thanks, the problem was solved but you reduced its complexity, you Rock man!.
    But still it wasn't giving proper results, the #'s were missing, the modified code is:

    Code:
        For iloop = 0 To List1.ListCount - 1
          TempArray() = Split(List1.List(iloop), "/")
          MyDate = DateSerial(TempArray(2), TempArray(0), TempArray(1))
          If (iloop = List1.ListCount - 1) Then
            que = que & "#" & Int(MyDate) & "#"
          Else
            que = que & "#" & Int(MyDate) & "#, "
          End If
        Next iloop
    
        que = que & ") AND end_time Is Not Null;"
    Thanks again

  5. #45
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Database application query problem

    I just tested, and it seems that Int returns a Date in this case - which is not what I intended, and is not safe either (even with the # characters).

    It would be better to convert the values to to Long instead, eg:
    Code:
            que = que & CLng(Int(MyDate))

  6. #46

    Thread Starter
    Member
    Join Date
    Aug 2008
    Posts
    39

    Re: Database application query problem

    Thanks so much Its almost done, without your help it couldn't have been done.

    I have another database related query, should i create another topic? Its related to retrieving selected fields of all records from the database and displaying it in the MSflexgrid for making reports. I tried to search it but was unable to find any topics related to it.

    Thanks
    Last edited by cool11; Sep 10th, 2008 at 07:53 AM.

  7. #47
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Database application query problem

    Unless it is specifically related to the original question in this thread, it would be best as a new thread.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width