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 2000 Forums
 Transact-SQL (2000)
 Multiple Joins

Author  Topic 

hutty
Starting Member

37 Posts

Posted - 2006-11-08 : 15:26:17
I have three views where I want two of the views to join the same column in view 1.

View 1 has a column name unit. I want to join View 2 unit and unit 2 on View 1 unit. In addition, I want to join View 3 unit on View 1 unit. All on the same query. Any ideas where I'm going wrong ?This is similar to what i have so far. Thanks.

SELECT DISTINCT
View1.Entity, View1.Accounts, View1.Scenario, View1.[Time Periods] AS Time_Periods,
View1.Years, View1.Amount, View1.Comment, View1.Adjustments, View1.unit AS Unit
FROM View1 INNER JOIN
View AS View2 ON View1.unit = View2.Unit OR View1.unit = View2.unit2 INNER JOIN
View3 ON View1.unit = View3.Unit
WHERE (View1.Scenario = @Scenario) AND (View1.Versions = 'Final') AND (View1.Years = @Years) AND
(View2.User_name = @user) AND (View1.Adjustments = 'input adj') AND (View1.[Time Periods] = @Time_Periods)

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-11-08 : 15:59:00
quote:
Originally posted by hutty

I have three views where I want two of the views to join the same column in view 1.

View 1 has a column name unit. I want to join View 2 unit and unit 2 on View 1 unit. In addition, I want to join View 3 unit on View 1 unit. All on the same query. Any ideas where I'm going wrong ?This is similar to what i have so far. Thanks.

SELECT DISTINCT
View1.Entity, View1.Accounts, View1.Scenario, View1.[Time Periods] AS Time_Periods,
View1.Years, View1.Amount, View1.Comment, View1.Adjustments, View1.unit AS Unit
FROM View1 INNER JOIN
View AS View2 ON View1.unit = View2.Unit OR View1.unit = View2.unit2 INNER JOIN
View3 ON View1.unit = View3.Unit
WHERE (View1.Scenario = @Scenario) AND (View1.Versions = 'Final') AND (View1.Years = @Years) AND
(View2.User_name = @user) AND (View1.Adjustments = 'input adj') AND (View1.[Time Periods] = @Time_Periods)



I'm afraid I have no idea what you are after .. some sample data and a better description of what you are trying to do will be helpful. Also, I highly doubt that you want that OR in your JOIN condition -- as a good rule of thumb, JOIN conditions should never include OR's.

- Jeff
Go to Top of Page

hutty
Starting Member

37 Posts

Posted - 2006-11-08 : 16:08:39
View1.unit contains the data I want to query against. View2 has two columns that may have a match in View1.unit. I'm trying to combine the two columns in View2 to query against View1.unit. Then there's View3 that has one column that I would like to query against View1.unit as well. So, in total there are three different columns from two different views that I would like to query on View1.unit.
Go to Top of Page
   

- Advertisement -