Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 14-09-2006, 12:32 PM
New kid on the block
 
Join Date: Sep 2006
Location: bangi
Posts: 3
Rep Power: 0
misz_nz is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 15-09-2006, 04:30 PM
New kid on the block
 
Join Date: Aug 2006
Location: Perak
Posts: 7
Rep Power: 0
chan0923 is on a distinguished road
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..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 15-09-2006, 04:37 PM
New kid on the block
 
Join Date: Aug 2006
Location: Perak
Posts: 7
Rep Power: 0
chan0923 is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 15-09-2006, 04:38 PM
New kid on the block
 
Join Date: Aug 2006
Location: Perak
Posts: 7
Rep Power: 0
chan0923 is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 17-10-2006, 12:31 PM
New kid on the block
 
Join Date: Sep 2006
Location: bangi
Posts: 3
Rep Power: 0
misz_nz is on a distinguished road
thanks for the help..really appreciate it..

err i'm not ukm students..plus i'm not a student anymore..
i'm ex-unitenians..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cheap Windows Host - ASP/ASP.net/PHP/MySQL/MSSQL (2 months free) Katatonic Web Hosting Offers 0 02-11-2006 01:58 PM
xHost SPECIAL => CFMX 7, ASP 2.0, ASP 1.1, PHP 4.0, PHP 5.0, MSSQL xhosts Web Hosting Offers 0 07-12-2005 11:07 PM
MYSQL & MSSQL : Can it run together ajamz Mamak Stall 8 04-07-2005 05:15 PM



All times are GMT +8. The time now is 11:02 PM. Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

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