Using SQLServer ver 7.0, two tables:
TableA = contains all inventory data
TableB = contains four fields: ID, source, date_from, date_to
This is where multiple range of dates are populated.
Sample 1:
1,'A','9/1/2004','9/30/2004'
Sample 2:
2,'A','1/1/2003','3/31/2003'
3,'A','10/1/2004','10/31/2004'
Data populated on TableB varies.
Sample SQL for Sample 1:
SELECT *
FROM TableA
WHERE inventory_date BETWEEN (select DATE_FROM from TableB) AND (select
DATE_TO from TableB)
Problem: How to approach sql statement based on Sample 2 above? 3 10989
B (no_spam@no_spam.com) writes: Using SQLServer ver 7.0, two tables: TableA = contains all inventory data TableB = contains four fields: ID, source, date_from, date_to This is where multiple range of dates are populated. Sample 1: 1,'A','9/1/2004','9/30/2004'
Sample 2: 2,'A','1/1/2003','3/31/2003' 3,'A','10/1/2004','10/31/2004'
Data populated on TableB varies.
Sample SQL for Sample 1: SELECT * FROM TableA WHERE inventory_date BETWEEN (select DATE_FROM from TableB) AND (select DATE_TO from TableB)
SELECT *
FROM TableA A
JOIN TableB B ON B.ID = A.ID
WHERE A.inventory_date BETWEEN B.date_from ABD B.date_to
But this is really a guess. If this does not answer your question, please
post:
o CREATE TABLE statements for your tables.
o INSERT statements with sample data.
o The expected result given the sample data.
That makes it possible to post a tested solution.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
On Mon, 8 Nov 2004 22:40:44 -0500, B wrote: Using SQLServer ver 7.0, two tables: TableA = contains all inventory data TableB = contains four fields: ID, source, date_from, date_to This is where multiple range of dates are populated. Sample 1: 1,'A','9/1/2004','9/30/2004'
Sample 2: 2,'A','1/1/2003','3/31/2003' 3,'A','10/1/2004','10/31/2004'
Data populated on TableB varies.
Sample SQL for Sample 1: SELECT * FROM TableA WHERE inventory_date BETWEEN (select DATE_FROM from TableB) AND (select DATE_TO from TableB)
Problem: How to approach sql statement based on Sample 2 above?
Hi B,
If you want it to return all inventory details with an inventory_date
between 1/1/2003 and 3/31/2003 or with an inventory date between 10/1/2004
and 10/31/2004, try this query:
SELECT A.Column1, A.Column2, ..., A.ColumnN
FROM TableA AS A
INNER JOIN TableB AS B
ON A.inventory_date BETWEEN B.DATE_FROM and B.DATE_TO
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
This is exactly solution I needed.
Many thanks for your time!
Bob If you want it to return all inventory details with an inventory_date between 1/1/2003 and 3/31/2003 or with an inventory date between 10/1/2004 and 10/31/2004, try this query:
SELECT A.Column1, A.Column2, ..., A.ColumnN FROM TableA AS A INNER JOIN TableB AS B ON A.inventory_date BETWEEN B.DATE_FROM and B.DATE_TO
Best, Hugo --
(Remove _NO_ and _SPAM_ to get my e-mail address) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Richard Hollenbeck |
last post by:
I'm trying to write some code that will convert any of the most popular
standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan
1908) and compare the first with the second and...
|
by: Adam |
last post by:
Hi All,
This may be a really obvious thing that I'm missing ... but if anyone can
help, I'd appreciate it.
I have MS Access 2000:
I'm using it for a CRM type database. I have a table with...
|
by: Joanie |
last post by:
I have a form that records dates of unavailability for a worker.
Based on what is entered in the simple table behind the form, many calculations take place to create employee "load" balance. Each...
|
by: rdemyan via AccessMonster.com |
last post by:
I have a need to highlight a date range in a bar chart. If the
"highlighting" is accomplished by changing the bar column color for the
specific months in the date range, that would be great.
...
|
by: norma.j.hildebrand |
last post by:
I have a database that has a field (performance standard), every
year the standard changed which was not a problem since we start out
each year with a blank database and just change the standards...
|
by: jrodcody |
last post by:
Hello:
I am trying to create multiple records in a table named tblTravel based on the input of a date range in two form controls. The inputs for the form are LastName, TravelDate, EndDate,...
|
by: 6afraidbecause789 |
last post by:
If able, can someone please help make a Where clause that strings
together IDs in a multi-select listbox AND includes a date range.
I wasn’t thinking when I used the code below that strings...
|
by: Vinda |
last post by:
Hi Bytes,
Using a previous question as a base Access 2000 Inserting multiple rows based on a date range.
I also wanted to insert multiple rows into a table according to a date range supplied by a...
|
by: cehlinger |
last post by:
I am trying to add multiple records based on a date range. I found some examples and have tried them but am getting errors and I can't seem to figure out what the problem is. I am not a VBA...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |