I am having some trouble reaching my intended results in combining information from a few tables. The easiest way to explain is with a dummy model
t1_____________ ___________
date - portfolio - group - contn
=============== =======
d1 A a 5
d1 A b 6
d1 A c 7
d2 A b 9
d2 A c 10
d2 A d 11
t2____________
availablegroups
===========
a
b
c
d
e
My objective is to get to either a query or table with
_______________ _______________ _
date - portfolio - group - contn
=============== =======
d1 A a 5
d1 A b 6
d1 A c 7
d1 A d 0 OR Null
d1 A e 0 OR Null
d2 A a 0 OR Null
d2 A b 9
d2 A c 10
d2 A d 11
d2 A e 0 OR Null
I've tried using t2 left join t1, but I end up losing the date and portfolio entries for groups that are available for use, but not used in the portfolio.
Bottom line -- I need a contribution number for every group that was available for every date available (the groups available are always the same), regardless of if there are transactions for that group
Any help?
~Chris
1 1407 NeoPa 32,566
Recognized Expert Moderator MVP
Not at all straightforward (some fun though), but I knocked up a quick test (which seems to work as required).
tblCont:
Date Group Contn
D1 A 5
D1 C 6
D1 E 7
D2 A 10
D2 B 11
D2 C 12
tblGroup:
Group
A
B
C
D
E - SELECT subAll.Date, subAll.Group, Nz([tblCont].[Contn],[subAll].[Contn]) AS Contn
-
FROM (SELECT [Date], [Group], 0 AS Contn
-
FROM tblGroup, (SELECT DISTINCT [Date]
-
FROM tblCont) AS subDate
-
ORDER BY [Date], [Group]) AS subAll LEFT JOIN tblCont ON (subAll.Date = tblCont.Date) AND (subAll.Group = tblCont.Group);
Produces :-
Date Group Contn
D1 A 5
D1 B 0
D1 C 6
D1 D 0
D1 E 7
D2 A 10
D2 B 11
D2 C 12
D2 D 0
D2 E 0
NB. Uses two levels of subquery. This is not an accident & I don't think it can be done (to work correctly) with anything less.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jgalzic |
last post by:
Hi,
I'm having trouble doing joins correctly on two tables. I've read up a
lot about the different types of joins and tried lots of variations on
inner, outer, and left joins with no avail. Something isn't correct
with my logic so could anyone give me some pointers on it?
I have 2 tables:
CourseRoster:
ID CourseID StudentID StudentType
|
by: Prem |
last post by:
Hi,
I am having many problems with inner join. my first problem is :
1) I want to know the precedance while evaluating query with multiple
joins.
eg.
select Employees.FirstName, Employees.LastName, TerritoryID,
Employees.EmployeeID,
RegionID, ProductID
from Employees
|
by: Chris |
last post by:
I'm having two general problems trying to do a JOIN. I have a table with
three fields {Code, Date, Amount}. Code+Date is a unique key. I'm trying
to get a rowset with 1) one row for each unique Code+Date pair, 2) and
with each row containing, {Code, Amount for Date-A and Amount for
Date-B}. Basically, I want to create two temp tables with the Amounts for
a specified Date and then Join them.
The problems are
1) I'm trying to do...
|
by: Bung |
last post by:
Hi,
I have a tricky sql statment I have to write (tricky for me) and I am
stuck. I'm having trouble with the following problem.
Table1 (Column a, Column b, Column c)
Table2 (Column a, Column b, Column c)
Table3 (Column a, Column b, Column c)
Table1 contains a row of value (1, 2, 3)
|
by: Geremy |
last post by:
Hi
Consider two tables
id1 code1
----------- -----
1 a
2 b
3 c
id2 code2 value
| |
by: Alex |
last post by:
Hi,
I have some problems with creating a query that will replace values in
one table from another one.
Table 1:
userName : refCode1 : refCode2
------------------------------
alex : 12 : 24
|
by: p175 |
last post by:
Hi people,
I have a stored procedure that creates many Global temporary
session tables. Into each of these tables go the results of various
processing using relational division all keyed and based on a common ID
from an ID session table. So we can have various session tables with
differing results but if they contain records, they are all keyed to
the common ID.
My problem now however is how do I report the overall findings of the
|
by: Matt C |
last post by:
I have rather complicated join I can't figure out (been mostly using
trial-and-error method...). I'll just explain with words first: (table
layout below)
Users are in categories. Depending on what category they're in, they
have a different set of functions that are *possible. There's an xref
table that defines which functions they actually have.
So e.g. user 1 is in category 4, and thus *might possess functions 6,7,
and 8. In fact she...
|
by: NeoPa |
last post by:
Introduction
Joins, in SQL, are a way of linking Recordsets together.
They involve restricting which data is returned in the output Recordset. When no join is specified but two Recordsets are, then a cartesian product is produced which specifies no restrictions. Conceptually, a JOIN is applied before any WHERE clause which may be specified.
NB. Full Outer Joins are not supported in Access (Jet) SQL.
When Recordsets are JOINed they...
|
by: shapper |
last post by:
Hello,
I am used to SQL but I am starting to use LINQ.
How can I create Left, Right and Inner joins in LINQ? How to
distinguish the different joins?
Here is a great SQL example:
http://www.codinghorror.com/blog/archives/000976.html
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |