If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query Help Please! Desperately

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-26-08, 03:51
judered judered is offline
Registered User
 
Join Date: Aug 2008
Posts: 2
Question Query Help Please! Desperately

i have table which have a date column, in addition to a set of other columns, all what i need a simple select query to get * from myTable where dateColumn value between (Start date) and (End date).
Reply With Quote
  #2 (permalink)  
Old 08-26-08, 03:56
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
SELECT col1
     , col2
     , col3
     , date_col
FROM   table_name
WHERE  date_col BETWEEN '2008-01-01T00:00:00.000' AND '2009-01-01T00:00:00.000'
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 08-27-08, 03:58
judered judered is offline
Registered User
 
Join Date: Aug 2008
Posts: 2
Question

Quote:
Originally Posted by georgev
Code:
SELECT col1
     , col2
     , col3
     , date_col
FROM   table_name
WHERE  date_col BETWEEN '2008-01-01T00:00:00.000' AND '2009-01-01T00:00:00.000'
Hi George
Firstly Thanks very much for your prompt answer.
however I used your method to run, still not working.
I have 2 tables: clients, clt_orders. is there any error with the statement below?
sql="select * from clients,clt_orders where clients.ID=clt_orders.client_id and clt_orders.date between '"&request("start_date")&"' and '"&request("end_date")&"' order by clt_orders.date"


by the way, date format is mm/dd/yyyy. does it matter with this? if so, how can I convert to right format. Thanks again!

Last edited by judered; 08-27-08 at 04:04.
Reply With Quote
  #4 (permalink)  
Old 08-27-08, 04:47
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
so what does the SQL that youy are sending to the server actually read as
guessing thats VB or a close relation... do a debug or message box of SQL variable.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 08-27-08, 07:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by judered
by the way, date format is mm/dd/yyyy. does it matter with this? if so, how can I convert to right format.
yes, it matters, it has to be yyyy-mm-dd

you would convert it into the correct format in whatever language that your are using that produces "&request("start_date")&" -- convert it there first, before sending the query to mysql
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 09-01-08, 08:59
Spudhead Spudhead is offline
Registered User
 
Join Date: Jan 2002
Posts: 189
Looks like VBScript ASP to me. So...

1. This will turn your date into something that MySQL understands:

Code:
<%
function addLeadingZero(s)
	dim rv : rv = s
	if len(cStr(s)) = 1 then rv = "0" & s
	addLeadingZero = rv
end function

function SQLDate(sDate)
	dim rv
	dim sDateDay, sDateMonth, sDateYear
	if isDate(sDate) then
		sDateDay = day(sDate)
		sDateMonth = month(sDate)
		sDateYear = year(sDate)
		rv = "'" & sDateYear & "-" & addLeadingZero(sDateMonth) & "-" & addLeadingZero(sDateDay) & "'"
	end if
	SQLDate = rv
end function
%>
2. Dropping unvalidated user input into a SQL statement is suicidal. Always check for malicious or plain stupid input before throwing it at your database.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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