Solved

SQL-clause

Posted on 1998-08-18
9
133 Views
Last Modified: 2010-04-30
Here is a criteria how I open my recordset:
criteria = "SELECT [Date], [Time], " + MyField + " FROM " + MyDB + " WHERE Time >='" + StartTime + "' AND Time <='" + EndTime + "' AND Date =#" + MyDate + "#"

I would like to add there one variable called Step.
I mean that if there is field in my database for every 1 minutes and I wanna open recordset only for every 15 minutes (Step is 15 minutes).
Is this even possible?? If it is, would you give me an example!

Thanks in advance!
0
Comment
Question by:majala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:wford
ID: 1429491
to clear this up a bit, you want to do what? only get the record if the step variable = 15, or every multiple of 15, or is this step information in the Time field?
0
 

Author Comment

by:majala
ID: 1429492
Here's example:
Recordset takes these datas now (if Starttime is 12:00, EndTime is 17:00 and Date is 24/6).
Date         Time       MyField
24.6         12:00      .....
24.6         12:01      .....
24.6         12:02      .....



24.6         17:00      .....
But I wanna take only these datas (if Step is 15):
Date         Time       MyField
24.6         12:00      .....
24.6         12:15      .....
24.6         12:30      .....
24.6         12:45      .....



24.6         17:00      .....

If this isn't possible, any other suggestions?
0
 
LVL 1

Expert Comment

by:wford
ID: 1429493
insert this into your where clause

AND (((datepart("n",Time)) mod 15) = 0)

bon chance
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:majala
ID: 1429494
That worked almost fine but there were a few things:

How I put it if I want that Step variable there:
AND (((datepart("n",Time)) mod " + Step + ") = 0), this didn't work?

This didn't work also:
(((datepart("n",Time)) mod 120) = 0)
Could it be something like:
(((datepart("h",Time)) mod 2) = 0)

Here is also one example how I want that recordset to open:
Date         Time       MyField
25.6         12:00      .....
26.6         12:00      .....
27.6         12:00      .....
28.6         12:00      .....

In my program there is a combobox where user can choose that Step-variable (10 minutes, 30 minutes, 1 hour, 1 day, 1 week)
0
 
LVL 1

Accepted Solution

by:
wford earned 80 total points
ID: 1429495
well the datepart variable may need to change, since it only returns the minute part of the date in this case "n", 10 and 30 minutes should work fine, but as you said, use a select case and one of these other formats for hours days etc... :
yyyy      Year
q      Quarter
m      Month
y      Day of year
d      Day
w      Weekday
ww      Week
h      Hour
n      Minute
s      Second
or you could use the datediff function and count the minutes between a start date/time and the time field like

AND ((DateDiff("n", #12:00#, time) ) mod 1440 = 0)

the 1440 here is == 24 hrs

hope this is enough
0
 

Author Comment

by:majala
ID: 1429496
If you could still tell me how I can do this:
AND (((datepart("n",Time)) mod " + Step + ") = 0)

I don't understand why this don't work. That Step variable is Variant.
0
 
LVL 1

Expert Comment

by:wford
ID: 1429497
ok 2 errors
1. syntax for "n" should be 'n'(my fault i generated this in access)
2. If datediff or datepart = 0 then then the mod will always be  crop up, since the bigger the number the more chance something = to 0, so datepart will return all times with XX:00 and datediff will return all times were for eg (12:00 = 12:00)
3. If datediff is big enough, then mulitple false values will will be a factor, and hence mod = 0

the best i can do is

Sqlstr = "SELECT * From Table1 Where (Table1.Date = Date) And (Table1.Time >= #12:00:00 PM#) And (Table1.Time <= #5:00:00 PM#)AND (((Datediff('n',#" & mydate & " " & starttime & "#,Table1.time) ) mod " & step & ")  = 0)"

where step = number of minutes in step eg. 1440 for one day

You may need to combine the table1 time and date to avoid erorrs as stated in 3. and 2.  
0
 

Author Comment

by:majala
ID: 1429498
Yes I noticed at the beginning that syntax "n" didn't work. I got it work when I did it like ""n"" but that 'n' seems to work also.
Now that "... mod "& step &"..." works also.

I didn't quite understand your second and third errors.

Thanks!
0
 
LVL 1

Expert Comment

by:wford
ID: 1429499
well, mod is a function that finds the remainder of 2 numbers, if the 1st number is 0 then there can be no remainder, so the expression evaluates to 0 and thus passes any record that matches.
so if you ask for the minutes datepart of 12:00 = 0 and, 0 mod 120 = 0, so the database thinks this record is ok and thus passes it back to your VB recordset

This also happens with datediff function if you give two times, if they are the same eg 12:00 and 12:00 then even though they have different dates and thus are different by n* 1440 minutes, the function knows nothing about their dates and just thinks they are on the same day, so you get 0 and the same problem as above.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

742 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