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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-06-27 : 08:26:22
|
| Neil writes "I have two tables, one containing the Names of people and criteria upon which they are measured, the other containing Sales data.The People looks something like :-Name Measurement CriteriaFred Yellow or BlueBill YellowJoe BlueAnne Red or YellowThe Sales Data looks like :-Color ValueYellow 1000Blue 2000Red 500The result I want is then :-Name ResultFred 3000Bill 1000Joe 2000Anne 1500Is there an easy way to do this, other than to run multiple passes of SQL ??Thx" |
|
|
Thrasymachus
Constraint Violating Yak Guru
483 Posts |
Posted - 2005-06-27 : 08:55:41
|
| to establish a many to many relationship the common practice is to use a "pass though table" (there are other terms for this) between name and measurement criteria.you would have a tables withtblName-----------------Nameid[name]tblMeasurementCriteria-------------------------MeasurementIdCriteriaValuetblNameMeausurementId-------------------------MeasurementIdNameidSELECT N.[name],SUM(M.Value) as ValueFROM tblName NJOIN tblNameMeausurementId NMON N.nameid = NM.nameidJOIN tblMeasurementCriteria MON M.MeasurementId = NM.MeasurementId GROUP BY N.[name]Sean RoussyPlease backup all of your databases including master, msdb and model on a regular basis. I am tired of telling people they are screwed. The job you save may be your own.I am available for consulting work. Just email me though the forum. |
 |
|
|
|
|
|