ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
Hello
Not sure exactly how to go about this, but have googled it to death in multiple ways, even googled the bits separately and can't figure out how to join them together.
For my VBA, it needs a recordset, currently loaded manually (export file from Oracle, loop through cells adding to recordset). But since I now have the SQL back-end access, I can pull the table directly.
This is going to help me a lot, but for one particular script I'd like to skip a step where currently, I use a VB Scripting Collection to identify unique records based on multiple fields. (e.g. 'If not MyColl.exists(VariTable(x,1) & VariTable(x,3)) then... [Recset.add...]'
Now the problem is, the 'groupings' I have are custom 'Time-bands'. Though all records are unique as to their time and date, I need unique examples of where each item by its ID falls into specific Time Categories. Specifically, 6am-7:59pm, 8pm-8:59pm, and 9pm-6am
If each of these groups is called 'Morning', 'Evening' and 'Nighttime', then if it finds 100 records with the same ID spread throughout the various times of the day, I need it to return just 3 (1 for each category)
Just to make it interesting, the Table I have access to is a read-only view table. So I can't Amend the table or add columns. I'm hoping I can do this all in my SELECT statement?
something like:
Is this possible? Sort only half know what I'm doing in SQL (Dangerous!!!)
Not sure exactly how to go about this, but have googled it to death in multiple ways, even googled the bits separately and can't figure out how to join them together.
For my VBA, it needs a recordset, currently loaded manually (export file from Oracle, loop through cells adding to recordset). But since I now have the SQL back-end access, I can pull the table directly.
This is going to help me a lot, but for one particular script I'd like to skip a step where currently, I use a VB Scripting Collection to identify unique records based on multiple fields. (e.g. 'If not MyColl.exists(VariTable(x,1) & VariTable(x,3)) then... [Recset.add...]'
Now the problem is, the 'groupings' I have are custom 'Time-bands'. Though all records are unique as to their time and date, I need unique examples of where each item by its ID falls into specific Time Categories. Specifically, 6am-7:59pm, 8pm-8:59pm, and 9pm-6am
If each of these groups is called 'Morning', 'Evening' and 'Nighttime', then if it finds 100 records with the same ID spread throughout the various times of the day, I need it to return just 3 (1 for each category)
Just to make it interesting, the Table I have access to is a read-only view table. So I can't Amend the table or add columns. I'm hoping I can do this all in my SELECT statement?
something like:
Code:
SELECT DISTINCT Col1_ItemID, (Col2_Time >= 06:00 AND Col2_Time <=19:59) OR (Col2_Time >= 20:00 AND Col2_Time <= 20:59) OR (Col2_Time >= 21:00) OR (Col2_Time <= 06:00) FROM table_name WHERE Date >= '20130215' ORDER BY Date DESC, Col2_Time Desc
Is this possible? Sort only half know what I'm doing in SQL (Dangerous!!!)