Unanswered: Issue With Updating Column From JOIN
I'm running into an issue when trying to update a column of a table with the results of a JOIN. Here is the query:
Here is the DDL for the table I'm trying to update:
[DF_TRUN] = (SELECT X.Trial_GUID,
COUNT(*)-1 --AS 'DF_TRUN'
FROM (SELECT T.Trial_GUID,
FROM EXTT_MR AS T
JOIN METT_MR AS TE
ON T.Trial_Entry_Defaults_GUID = TE.Trial_Entry_Defaults_GUID
JOIN Trial_Stats_Constant_MR AS TSC
ON T.Trial_GUID = TSC.Trial_GUID
--WHERE T.Trial_GUID = TSC.Trial_GUID
GROUP BY T.Trial_GUID, TE.Trial_Entry_GUID) AS X
GROUP BY X.Trial_GUID)
The Trial_GUID is unique. The query essntially performs a count of rows in the EXTT / METT table, joined by the Trial_GUID. Here's an example of the output:
CREATE TABLE [dbo].[Trial_Stats_Constant_MR](
[Trial_GUID] [uniqueidentifier] NULL,
[DF_MINN] [int] NULL,
[DF_REPN] [int] NULL,
[DF_TOTN] [int] NULL,
[DF_TRUN] [int] NULL,
[Entry_Count] [int] NULL,
[Create_Date] [datetime] NULL
) ON [PRIMARY]
Trial_GUID (No column name)
In the Trial_Stats_Constant table, I just want to update the DF_TRUN column with the count based on each individual Trial_GUID.
When running the query, I get:
I know it's complaining about the fact that it's trying to update NENT column but there is more than one result.
Msg 512, Level 16, State 1, Line 1
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.
Just trying to figure out how to tell the query to match the Trial_GUID's
"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."