Any help would be appretiated here...
I have 3 tables and have been assigned the task of denormalizing the data to help with history queries. I want to write an SQL that will take data from the Third Table and put it into the first table based on the Table2 Record which links the first and third. Here is the Sample Table Set ups...
[tt]
[Table1]
[BUID]
[Name]
[T_Table2]
[BUID]
[UID]
[T_Table3]
[UID]
[Name]
[/tt]
So what I want to do is take the ObjectName Data that is in Table3, and Populate it into Table1, based on the BUID from Table1 and 2 and the UID between 2 and 3.
Here is what I have:
[tt]
UPDATE Table1 SET [Name]=(
SELECT DISTINCT(T3.Name) AS [Name]
FROM Table1 AS T1
INNER JOIN Table2 AS T2 ON T2.BUID = T1.BUID
INNER JOIN Table3 AS T3 ON T3.UID = T2.UID)
[/tt]
But it is Returning the error:
Server: Msg 512, Level 16, State 1, Line 39
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
I did Counts and Distinct Counts on all of these tables...
[tt]SELECT COUNT(DISTINCT(BUID)), COUNT(BUID) FROM Table1
Results: 7078, 7078
SELECT COUNT(DISTINCT(BUID)), COUNT(BUID) FROM Table2
Results: 3561, 3561
[/tt]
Casper
There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
I have 3 tables and have been assigned the task of denormalizing the data to help with history queries. I want to write an SQL that will take data from the Third Table and put it into the first table based on the Table2 Record which links the first and third. Here is the Sample Table Set ups...
[tt]
[Table1]
[BUID]
[Name]
[T_Table2]
[BUID]
[UID]
[T_Table3]
[UID]
[Name]
[/tt]
So what I want to do is take the ObjectName Data that is in Table3, and Populate it into Table1, based on the BUID from Table1 and 2 and the UID between 2 and 3.
Here is what I have:
[tt]
UPDATE Table1 SET [Name]=(
SELECT DISTINCT(T3.Name) AS [Name]
FROM Table1 AS T1
INNER JOIN Table2 AS T2 ON T2.BUID = T1.BUID
INNER JOIN Table3 AS T3 ON T3.UID = T2.UID)
[/tt]
But it is Returning the error:
Server: Msg 512, Level 16, State 1, Line 39
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
I did Counts and Distinct Counts on all of these tables...
[tt]SELECT COUNT(DISTINCT(BUID)), COUNT(BUID) FROM Table1
Results: 7078, 7078
SELECT COUNT(DISTINCT(BUID)), COUNT(BUID) FROM Table2
Results: 3561, 3561
[/tt]
Casper
There is room for all of gods creatures, "Right Beside the Mashed Potatoes".