|
-
Oct 7th, 2000, 11:03 AM
#1
Thread Starter
Addicted Member
Hello!
I need some help with SQL statements. My question is:
How can I retrieve from my DB those records that were last accessed between two dates, let's say that I have to retrive all records from 2. june 2000 to 1. october 2000.
Does anyone know how?
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Oct 7th, 2000, 11:12 AM
#2
I can give you an example using Jet/DAO. If you are using SQL Server/ADO or some other setup the code would be different.
Assuming there is a Date/Time field in your records, you could do something like the following:
Code:
Dim dbs As Database
Dim rst As Recordset
Dim strSQL As String
Set dbs = OpenDatabase("C:\Whatever\MyData.mdb")
strSQL = "SELECT * FROM MyTable " _
& "WHERE DateField BETWEEN #6/2/2000# AND #10/1/2000#"
Set rst = dbs.OpenRecordset(strSQL)
' "rst" is now a recordset containing the filtered records
' you want to process ...
Do Until rst.EOF
'whatever
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set dbs = Nothing
"It's cold gin time again ..."
Check out my website here.
-
Oct 7th, 2000, 11:17 AM
#3
Thread Starter
Addicted Member
And if I don't have date fields?
Let's say that I have text fields and I want to retrieve just those records that start with charachters between A and K? Does previous method work here too?
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
-
Oct 7th, 2000, 11:29 AM
#4
Yes. You could use:
Code:
strSQL = "SELECT * FROM MyTable " _
& "WHERE Left(SomeField, 1) BETWEEN 'A' AND 'K'"
Note: For Jet (Access) databases, you can use VB functions (such as "Left") in the SQL. The SQL for other DBMS's have their own specific functions that achieve the same results as the corresponding VB function.
"It's cold gin time again ..."
Check out my website here.
-
Oct 7th, 2000, 02:51 PM
#5
Thread Starter
Addicted Member
I use DataEnvironment/ADO. Will that work also with this or not?
Zvonko Bostjancic
Ilirska Bistrica, Slovenia
[email protected]
Using VS6 Professional with SP3
Programming mostly in VB and I've started to learn VC++ & MFC
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|