SQLTeam.com | Weblogs | Forums

Complex Query

I've made an attempt but it's not working as needed.

Update t1
Set t1.CandidateColumn = t2.ColumnName
From #TempTablesNotInTablesDeletedFrom as t1
Inner Join ColumnAttributes as t2
ON t1.TableName = t2.TableView
WHERE t1.CandidateColumn = null AND Exists(Select t2.ColumnName from ColumnAttributes where ColumnName = 'QuoteID')

For every t1 row, there will be multiple rows in t2. I want to update t1.CandidateColumn with the ColumnName in t2 IF it is a value of QuoteID. That's what I'm trying to do in the AND EXISTS... clause.
I think I'm close but need a bit of help.

Thanks

Update t1
Set t1.CandidateColumn = t2.ColumnName
From #TempTablesNotInTablesDeletedFrom as t1
Inner Join ColumnAttributes as t2
ON t1.TableName = t2.TableView AND t2.ColumnName = 'QuoteID'
WHERE t1.CandidateColumn IS NULL --<<-- you must use "IS NULL", *not* "= null"
1 Like

Thanks, @ScottPletcher. As usual, your solution works perfectly.