Results 1 to 5 of 5

Thread: mssql..pls help me

  1. #1
    Join Date
    Sep 2006
    Location
    bangi
    Posts
    3
    Rep Power
    0

    Unhappy mssql..pls help me

    akum..
    sy nk tanye camne nk kuarkan tarikh terakhir dlm bulan yg kite dh select from db?cnth mcm statement kt bwh nih kn..

    SELECT TARIKH FROM BILTUNAI WHERE (NOPENGEDAR = '12345') AND (YEAR(TARIKH) = '2006') AND (MONTH(TARIKH) = '07') ORDER BY TARIKH

    so dia punye output:

    1/7/2006
    14/7/2006
    23/7/2006

    so skrg sy nk output yg dikuarkan ialah hari terakhir berdasarkan bulan yg kite select.cnth klu output utk kt atas tuh,sy nk dia display 31/7/2006.

    ade sape2 leh tolong sy?thanks in advance..
    Last edited by misz_nz; 14-09-2006 at 12:38 PM.

  2. #2
    Join Date
    Aug 2006
    Location
    Perak
    Posts
    8
    Rep Power
    0
    Quote Originally Posted by misz_nz
    SELECT TARIKH FROM BILTUNAI WHERE (NOPENGEDAR = '12345') AND (YEAR(TARIKH) = '2006') AND (MONTH(TARIKH) = '07') ORDER BY TARIKH
    I suggest u use either a TOP or LIMIT function.

    Code:
    SELECT TOP 1 TARIKH FROM BILTUNAI WHERE 
    (NOPENGEDAR = '12345') AND 
    (YEAR(TARIKH) = '2006') AND 
    (MONTH(TARIKH) = '07') 
    ORDER BY TARIKH DESC
    Sort the result in an descending order so that the largest date will be displayed on the top, then limit your result to 1.

    The other way is

    Code:
    SELECT TARIKH FROM BILTUNAI WHERE 
    (NOPENGEDAR = '12345') AND 
    (YEAR(TARIKH) = '2006') AND 
    (MONTH(TARIKH) = '07') 
    ORDER BY TARIKH DESC LIMIT 1
    Both query will return the correct result if I'm not mistaken. Hope this helps..

  3. #3
    Join Date
    Aug 2006
    Location
    Perak
    Posts
    8
    Rep Power
    0
    Did u mean when u select january 2006, the result will be the last date of january IN YOUR DATABASE RECORD, or you want EXACTLY the last day of January (31 Janury 2006) ?

    If your case is the second, then you should use php date() function, instead of mysql select. The suggestion above only works if u want the last date in your database.

  4. #4
    Join Date
    Aug 2006
    Location
    Perak
    Posts
    8
    Rep Power
    0
    Also another things out of my curiosity, since your location is in bangi, I wonder if u're a UKM student ? Cause I'm also from UKM

  5. #5
    Join Date
    Sep 2006
    Location
    bangi
    Posts
    3
    Rep Power
    0
    thanks for the help..really appreciate it..

    err i'm not ukm students..plus i'm not a student anymore..
    i'm ex-unitenians..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MSSQL or MySQL
    By Laughingman in forum Website Programming
    Replies: 7
    Last Post: 23-09-2008, 03:40 PM
  2. ASP.NET & MSSQL Freelancer wanted.
    By josephccl in forum Looking To Hire
    Replies: 1
    Last Post: 23-02-2008, 02:24 AM
  3. Cheap Windows Host - ASP/ASP.net/PHP/MySQL/MSSQL (2 months free)
    By Katatonic in forum Web Hosting Offers
    Replies: 0
    Last Post: 02-11-2006, 01:58 PM
  4. Replies: 0
    Last Post: 07-12-2005, 11:07 PM
  5. MYSQL & MSSQL : Can it run together
    By ajamz in forum Mamak Stall
    Replies: 8
    Last Post: 04-07-2005, 05:15 PM

Posting Permissions

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

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112