Results 1 to 10 of 10

Thread: SQL(Pretty hard one)

  1. #1

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179

    Talking

    Hi all
    Anyone out there knows any SQL for comparing dates?
    for example if i type in 1/1/2000 and 1/12/2000 it will display all the record between those date

    Code:
    Data1.RecordSource = " select productname,month, count(productcodeno) as count, SUM(orderdeliver)AS sum from customerpricelist  where month  = #" & strDate & "# and #" & strdate2 & "# group by productname,month"
      
    
     Data1.Refresh
    That is the current code i have but it fails to do the job


  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ....

    Actually, I had posted the reply to a similar question somewhere else, might as well repeat myself.

    CoMMiE, what you need to do is: convert strDate to a format, say 'mm/dd/yyyy' using the Format() function. Then in your query, convert the date field into the same format using the SQL date functions. I don't have any experience working with SQL, so I shall quote Oracle example:

    Select * from Customers where TO_CHAR(BirthDate, 'mm/dd/yyyy') = '" & Format(MyDate, "mm/dd/yyyy") & "'"
    See if it works.

    By the way, you haven't answered my question, I think. Are you non-US ?

    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    Well honeybee thanks for the reply again!!!!!

    By the way i am using a text box in VB to let the user enter the date so it is unecessery for me to convert the textbox format

    Yeah i am a Non-US good guess thought

  4. #4
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hi commie

    You can use The BETWEEN comparison or the IN comparison

    SELECT *
    FROM tbltest
    WHERE datet BETWEEN #1/2/2000# AND #1/3/2000#

    Will return anything fields in that date range

    SELECT *
    FROM tbltest
    WHERE datet In (#1/2/2000#,#1/3/2000#)

    Will return any fields that have the date's put in. It is a quicker way of rightinh datet = #1/2/2000# OR datet = #1/3/2000#

    Hope this helps

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  5. #5

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    Thanks for the reply Ianpbaker
    But the sugestion you sugest give me a wrong result for example when i key in the date 1/1/1999 and 3/1/1999 it came out the query which is for 2/3/1999 which is totally out of the target

    here is my updated code below
    Code:
    Data1.RecordSource = " select * from customerpricelist  where month  between #" & strDate & "# and #" & strdate2 & "#"
    Data1.Refresh
    i check and analyse the above code many times but i still get the same result

    can anyone out there point out what have i done wrong

  6. #6
    New Member
    Join Date
    Aug 2000
    Posts
    2

    Dates "Between" and or "In"

    The reason for not getting the right output is because your system is using the International dating system. Switch to an English-American dating system and try the reponses from before. Or Think about this 1/1/1999 - 3/1/1999 are these dd/mm/yyyy? and if so then 2/1/1999 would have been the correct output. Hope tis helps.
    Anthony

  7. #7

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    well thanks a lot vandyck_anthony
    you have finaly pointed out the problem, it all started because SQL assume i am using the AMERICAN date system while all the while i have been following the BRITISH date standard.

    so the question now is how can i make the SQL compare dates in dd/mm/yyyy instead of the AMERICAN mm/dd/yyyy

    i cant belive the date standard have cause so much headeche for me

  8. #8
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hi Commie

    Go into control panel and click on regional settings and make sure it set to english(Brittish) then click on the date tab and it should show dd/mm/yyyy.

    This should sort out your problem

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  9. #9

    Thread Starter
    Addicted Member CoMMiE's Avatar
    Join Date
    Jul 2000
    Location
    Malaysia, Kuala Lumpur
    Posts
    179
    Thanks a lot Ianpbaker
    By setting the windows reginal setings it seems that it only solve half of the problem, after i experiment more with the query i found out that the SQL has follow the BRITTISH date format but the main problem now is VB is still folowing the AMERICAN date format!!!!!!

    So the question now is can i do anything so that VB will assume that i am following the BRITTISH date format ?

  10. #10
    New Member
    Join Date
    Aug 2000
    Posts
    2

    Talking Format 4mat and For Matt

    you can use the syntax of
    Format(#dd/mm/yyyy#) anytime
    esp when doing a conversion
    or comparison of data.
    Hope this helps...
    Anthony

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