troubleshooting Question

Error running an update statement with a pivot table in SQL Server

Avatar of Declan Basile
Declan BasileFlag for United States of America asked on
Microsoft SQL ServerSQL
2 Comments1 Solution67 ViewsLast Modified:
In SQL Server 2012, why do I get the error "The multi-part identifier "T1.Text1" could not be bound." when I run the following statement:

UPDATE DBGUIds SET T1.Text1 = PT.Text1 FROM DBGUIds T1 INNER JOIN
      (SELECT InstanceId, EntityId, Text1
      FROM
      (SELECT InstanceId, EntityId, FieldName, Value FROM TB WHERE TableName = 'DBGUIds') T3      
      PIVOT
      (
            MAX(Value) FOR FieldName IN (Text1)
      ) V) PT ON T1.int1 = PT.InstanceId


Please note that the following statement works ...
      SELECT T1.Text1, PT.Text1 FROM DBGUIds T1 INNER JOIN
      (SELECT InstanceId, EntityId, Text1
      FROM
      (SELECT InstanceId, EntityId, FieldName, Value FROM TB WHERE TableName = 'DBGUIds') T3      
      PIVOT
      (
            MAX(Value) FOR FieldName IN (Text1)
      ) V) PT ON T1.int1 = PT.InstanceId

and outputs ...
Text1  Text1
Null     10
Null     20
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros