ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SQL (https://www.excelbanter.com/excel-programming/394443-sql.html)

C. Bailey

SQL
 
I am fairly new at SQL and VBA.

I am working with a very large database. For simplicity sake, let's assume
the database is for a rental company and it records the number of kilometers
driven on different dates and for different cars.

I have created a query that can successfully pull the data for one car
between given dates. But what I would like to do is pull data for many cars
(not all cars) for different dates and organize them in a table like this:


Car 1 Car 3 Car 4
1/1/2007 50 105 104
1/2/2007 34 15 30
1/3/2007 5 157 26


I could take the query I have, and create a VBA loop to query for every car
I want. Is this the most efficient way to do this? It seems "wasteful".

Thank you,
Chris



barnabel

SQL
 
you can do:
car in ("car 1","car 3","car 4")

then look at pivot tables to arange the results.

Peter Richardson

"C. Bailey" wrote:

I am fairly new at SQL and VBA.

I am working with a very large database. For simplicity sake, let's assume
the database is for a rental company and it records the number of kilometers
driven on different dates and for different cars.

I have created a query that can successfully pull the data for one car
between given dates. But what I would like to do is pull data for many cars
(not all cars) for different dates and organize them in a table like this:


Car 1 Car 3 Car 4
1/1/2007 50 105 104
1/2/2007 34 15 30
1/3/2007 5 157 26


I could take the query I have, and create a VBA loop to query for every car
I want. Is this the most efficient way to do this? It seems "wasteful".

Thank you,
Chris




Tim Williams

SQL
 
Try posting the SQL you're using right now.
Hard to suggest anything if we don't know how your database is organized.

Tim

"C. Bailey" wrote in message
news:Qtwri.70300$tB5.46959@edtnps90...
I am fairly new at SQL and VBA.

I am working with a very large database. For simplicity sake, let's
assume the database is for a rental company and it records the number of
kilometers driven on different dates and for different cars.

I have created a query that can successfully pull the data for one car
between given dates. But what I would like to do is pull data for many
cars (not all cars) for different dates and organize them in a table like
this:


Car 1 Car 3 Car 4
1/1/2007 50 105 104
1/2/2007 34 15 30
1/3/2007 5 157 26


I could take the query I have, and create a VBA loop to query for every
car I want. Is this the most efficient way to do this? It seems
"wasteful".

Thank you,
Chris




GysdeJongh

SQL
 
"C. Bailey" wrote in message
news:Qtwri.70300$tB5.46959@edtnps90...
I am fairly new at SQL and VBA.

I am working with a very large database. For simplicity sake, let's
assume the database is for a rental company and it records the number of
kilometers driven on different dates and for different cars.

I have created a query that can successfully pull the data for one car
between given dates. But what I would like to do is pull data for many
cars (not all cars) for different dates and organize them in a table like
this:


Car 1 Car 3 Car 4
1/1/2007 50 105 104
1/2/2007 34 15 30
1/3/2007 5 157 26


Hi C. Bailey,
I think I have the same problem : a very large database and some times I
want to extract a specific list.What I do is make a new table in the
Database , sometimes just manually if the list is not that long , sometimes
in VBA or in Excel.The table above would be a perfect example of what I
mean.Than call this new table : ProjectX.Than do a query which contains a
join (using the date in your example )between the database and the ProjectX
table where the ProjectX table is the feeder table.

hth
Gys




All times are GMT +1. The time now is 12:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com