Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 join or union

Author  Topic 

tirby
Starting Member

3 Posts

Posted - 2009-04-20 : 13:07:27
I’m not sure how to use the join statement in this instance. I have been able to use vb2008 to get the data into data sets and process it from there but that used three separate sql queries and since I am working off satellite internet connections I need to watch the number of queries

I have two tables that I need to combine into a view.
The first table is called inspection
Lease Chemical Date level
Well1 Foamer 01/01/2009 48
Well1 SI 01/01/2009 57
Well2 SI 01/01/2009 36
Well1 Foamer 01/15/2009 45
Well1 SI 01/15/2009 53
Well2 SI 01/15/2009 32
Well1 Foamer 01/30/2009 40
Well1 SI 01/30/2009 50
Well2 SI 01/30/2009 30

The second table is called Delivery
Lease Chemical Date Amount
Well1 Foamer 01/13/2009 25
Well1 SI 01/13/2009 20
.
What I need is a view that looks like this

Lease Chemical Date1 Level Date 2 Level TotalDelivered
Well1 Foamer 1/01/2009 48 01/15/2009 45 25
Well1 Foamer 1/15/2009 45 01/30/2009 40 0
Well1 SI 1/01/2009 57 01/15/2009 53 20
Well1 SI 1/15/2009 53 01/30/2009 50 0
Well2 SI 1/01/2009 36 01/15/2009 32 0
Well2 SI 1/15/2009 32 01/30/2009 30 0

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-04-20 : 13:47:15
USe Pivot or Crosstab queries. Search and you will find lot of them.
Go to Top of Page
   

- Advertisement -