Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

database query - can't get this to work :(

Thread Tools
 
Search this Thread
 
Old 14 September 2004, 09:25 AM
  #1  
midget1500
Scooby Regular
Thread Starter
 
midget1500's Avatar
 
Join Date: Sep 2001
Location: Bangor, Northern Ireland
Posts: 2,033
Likes: 0
Received 0 Likes on 0 Posts
Default database query - can't get this to work :(

simplistic view

3 tables
--------

booking accomodation activity
------- ------------- --------

id id id
num_people status status
total total
deposit deposit

where the id is common across all tables
status = paid or invoiced
debt = total-deposit

so, if i want to know the debt for each booking (i.e. where status = invoiced) how do i go about it. i've tried union queries, nested sql, etc but can't get a solution.

cheers
steven
Old 14 September 2004, 09:43 AM
  #2  
Frosty The Snowman
Scooby Regular
 
Frosty The Snowman's Avatar
 
Join Date: Jun 2004
Location: Bedfordshire
Posts: 528
Likes: 0
Received 0 Likes on 0 Posts
Default

Sorry if I am misunderstanding but it looks like you can just get the information from the one table, accomodation, unless the tabbing is really off the wall.

select id, (total-deposit)
from accomodation
where status = "invoiced"

If the tables are different from what they look like let me know and I'll have another bash.


Mark

Mark
Old 14 September 2004, 11:36 AM
  #3  
midget1500
Scooby Regular
Thread Starter
 
midget1500's Avatar
 
Join Date: Sep 2001
Location: Bangor, Northern Ireland
Posts: 2,033
Likes: 0
Received 0 Likes on 0 Posts
Default

sorry, the accomodation element may have a status of paid, but perhaps the activity is invoiced but not paid, so the status's and amounts outstanding can differ.
Old 14 September 2004, 11:57 AM
  #4  
SCOSaltire
Scooby Regular
 
SCOSaltire's Avatar
 
Join Date: Mar 2001
Posts: 1,809
Likes: 0
Received 0 Likes on 0 Posts
Default

dont know if this will definately work as ive tried it blind...

select booking.id, isnull(accomodation.total,0) + isnull(activity.total,0) as debt
from booking
join accomodation on
(booking.id=accomodation.id and accomodation.status='invoiced')
join activity on
(booking.id=activity.id and activity.status='invoiced')
Old 14 September 2004, 06:37 PM
  #5  
tommy1980
Scooby Newbie
 
tommy1980's Avatar
 
Join Date: Apr 2004
Posts: 21
Likes: 0
Received 0 Likes on 0 Posts
Default

quickly went through it and came up with this hopefully this is right


select booking.id,
(isnull(accomodation.total,0) - isnull(accomodation.deposit,0)) + (isnull(activity.total,0) - isnull(activity.deposit,0)) as debt
from booking, accomodation, activity where booking.id = accomodation.id and booking.id = activity.id and
(accomodation.status = 'invoiced' or activity.status = 'invoiced')
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Darrell@Scoobyworx
Trader Announcements
26
30 January 2024 01:27 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
38
17 July 2016 10:43 PM
alex_00s
Drivetrain
2
26 September 2015 06:07 PM
StueyBII
General Technical
0
25 September 2015 05:58 PM
Littleted
Computer & Technology Related
0
25 September 2015 08:44 AM



Quick Reply: database query - can't get this to work :(



All times are GMT +1. The time now is 06:01 PM.