palserv
asked on
How to make query to get data between specific date duration ?
Hi,
iv 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 value) and (End value).
note, i'm using SQl server 2000
thanks,
iv 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 value) and (End value).
note, i'm using SQl server 2000
thanks,
select * from myTable where dateColumn between StartValue and EndValue
ASKER
thanks for your answer,
but i need to know where the error in this code
Select * FROM myTable WHERE Convert(DateTime, Date_of_Documentation,103) >= Convert(DateTime,dateTimeP icker1.Val ue,103) and Convert(datetime,Date_of_D ocumentati on,103) <= Convert(DateTime,dateTimeP icker2.val ue,103)
i'm using visual studio 2005 and c# in development.
but i need to know where the error in this code
Select * FROM myTable WHERE Convert(DateTime, Date_of_Documentation,103)
i'm using visual studio 2005 and c# in development.
Well, it kind of looks OK,
103 is dd/mm/yyyy, so, the convert is assuming that the datavalues can be readily expressed in that format. No worries for a dattime construct, but for a string / char / varchar (etc) then the content of that variable must must the format that the convert is told to use...
so, do not need to convert Date_Of_Documentation if already a legitimate datetime column.
I would be looking at :
Select * FROM myTable WHERE Date_of_Documentation btween Convert(DateTime,dateTimeP icker1.Val ue,103) and Convert(DateTime,dateTimeP icker2.val ue,103)
Now, if there is also a time component, then we can / will need to start manipluating a bit more.
What is the error you are getting ? Is the date_of_documentation a legit datetime ? what is the content of the variables datetimepicker1 and 2 ?
103 is dd/mm/yyyy, so, the convert is assuming that the datavalues can be readily expressed in that format. No worries for a dattime construct, but for a string / char / varchar (etc) then the content of that variable must must the format that the convert is told to use...
so, do not need to convert Date_Of_Documentation if already a legitimate datetime column.
I would be looking at :
Select * FROM myTable WHERE Date_of_Documentation btween Convert(DateTime,dateTimeP
Now, if there is also a time component, then we can / will need to start manipluating a bit more.
What is the error you are getting ? Is the date_of_documentation a legit datetime ? what is the content of the variables datetimepicker1 and 2 ?
ASKER
Hi,
i'v tried your idea, but i still got this errer message
"The SELECT statment include a reserved word or an argument name that is missplesed or missing or the punctuation is incorrect"
this is my statment :
query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimeP icker1.Val ue,103)AND Convert(DateTime,dateTimeP icker1.Val ue,103) and Convert(datetime,dateTimeP icker2.Val ue,103)";
where Date_of_Documentation is a Date/Time data type
i'v tried your idea, but i still got this errer message
"The SELECT statment include a reserved word or an argument name that is missplesed or missing or the punctuation is incorrect"
this is my statment :
query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimeP
where Date_of_Documentation is a Date/Time data type
one too many datetimepicker1:
instead of:
query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimeP icker1.Val ue,103)AND Convert(DateTime,dateTimeP icker1.Val ue,103) and Convert(datetime,dateTimeP icker2.Val ue,103)";
use :
query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimeP icker1.Val ue,103) and Convert(datetime,dateTimeP icker2.Val ue,103)";
still need to handle the time component properly, but better off just changing one thing at a time...
instead of:
query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimeP
use :
query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimeP
still need to handle the time component properly, but better off just changing one thing at a time...
ASKER
error msg : 'System.Convert' is a 'type' but is used like a 'variable' :(
D'oh, You will have to put the contents of the datetimepicker1.value into the string... kind of like...
" FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,'"+dateTi mePicker1. Value+"',1 03) and Convert(datetime,'"+dateTi mePicker2. Value+"',1 03)";
will need to possibly convert the value so it can be concatenated...
the result should be the equivelant of:
" FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,'01/01/20 08',103) and Convert(datetime,'02/02/20 08',103)";
" FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,'"+dateTi
will need to possibly convert the value so it can be concatenated...
the result should be the equivelant of:
" FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,'01/01/20
ASKER
well i'v get this result " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,'01/01/20 08',103) and Convert(datetime,'02/02/20 08',103)"; completely
but this result cause an OleDbException in this message "Undefined function ''Convert in this Expression "
i'm so confusing, all my problem is some of quotes which i didnt know there right place
but this result cause an OleDbException in this message "Undefined function ''Convert in this Expression "
i'm so confusing, all my problem is some of quotes which i didnt know there right place
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.