Solved

How to make query to get data between specific date duration ?

Posted on 2008-06-15
9
969 Views
Last Modified: 2010-10-26
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,
0
Comment
Question by:palserv
  • 4
  • 4
9 Comments
 
LVL 4

Expert Comment

by:vseth
ID: 21788016
select * from myTable where dateColumn between StartValue and EndValue
0
 

Author Comment

by:palserv
ID: 21788477
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,dateTimePicker1.Value,103) and Convert(datetime,Date_of_Documentation,103) <= Convert(DateTime,dateTimePicker2.value,103)

i'm using visual studio 2005 and c# in development.
0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 21788598
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,dateTimePicker1.Value,103) and Convert(DateTime,dateTimePicker2.value,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 ?
0
 

Author Comment

by:palserv
ID: 21791271
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,dateTimePicker1.Value,103)AND Convert(DateTime,dateTimePicker1.Value,103) and Convert(datetime,dateTimePicker2.Value,103)";

where Date_of_Documentation is a Date/Time data type
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 51

Expert Comment

by:Mark Wills
ID: 21791528
one too many datetimepicker1:

instead of:

query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimePicker1.Value,103)AND Convert(DateTime,dateTimePicker1.Value,103) and Convert(datetime,dateTimePicker2.Value,103)";

use :

query += " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,dateTimePicker1.Value,103) and Convert(datetime,dateTimePicker2.Value,103)";

still need to handle the time component properly, but better off just changing one thing at a time...
0
 

Author Comment

by:palserv
ID: 21792104
error msg : 'System.Convert' is a 'type' but is used like a 'variable'  :(

0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 21794256
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,'"+dateTimePicker1.Value+"',103) and Convert(datetime,'"+dateTimePicker2.Value+"',103)";

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/2008',103) and Convert(datetime,'02/02/2008',103)";
0
 

Author Comment

by:palserv
ID: 21800940
well i'v get this result " FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,'01/01/2008',103) and Convert(datetime,'02/02/2008',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
0
 
LVL 51

Accepted Solution

by:
Mark Wills earned 500 total points
ID: 21802222
You are using SQL 2000 right ?

open up query analyser and simply paste :

SELECT * FROM Damaged_factories WHERE Date_of_Documentation BETWEEN Convert(DateTime,'01/01/2008',103) and Convert(datetime,'02/02/2008',103)

and see what happens ?
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now