SQL Recipes (Beta II)
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
  #1 (permalink)  
Old 07-11-2006, 07:51 AM
Berny
 
Posts: n/a
Default Access dialect question:

difficult pivot?


hi!

for a pivot view in our project database i need to join two tables.

table bills
----
customer_id project_id month year price

table payments
----
customer_id month year payment

desired result
----
customer_id project_id month year price payment

desired example:
customer 2 is participating in project 2 & 3. - payment should be equal in line 2 and 3.
----
row 1: 1 2 1 2006 0 300
row 2: 1 2 2 2006 1,000 500
row 3: 1 3 2 2006 150, 500
row 4: 1 2 3 2006 750 0

if i use the code below i always miss line 1 because there is no entry for the second table. of course not, [...]

SELECT customer_id, project_id, month, year, price, (SELECT price FROM bills WHERE bills.customer_id=payments.customer_id AND bills.month=payments.month AND bills.year=bills.year) FROM payments

i didn't figure out how to solve that in access. - i know it would be easier in a stored procedure, though, do you have an idea to solve my gordian knot?

cheers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
Be the first to answer this question! Click on the 'Post Reply' button below.
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Moderation Tools:



All times are GMT. The time now is 05:00 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2007 SQL Recipes

1 2 3 4 5 6 7