This is in SQL server 2012. I'm on Sever Management studio. I have multiple servers that have multiple databases that I need to feed it a varying list of Database names to pull back a sum of a size field. At the moment @sql2 updates the BR_ProductionSize to the actual select statement instead of the answer to that statement.
DECLARE @TempCaseArtifactID NVARCHAR(60)
DECLARE @sql2 NVARCHAR(200)
DECLARE @answer NVARCHAR(200)
set @TempCaseArtifactID = (select '[EDDS'+BR_CaseArtifactid+'].[EDDSDBO].[File]' from #BRFindSizes where UpdateCompleted = '2')
set @sql2 = '(select SUM(size) FROM '+@TempCaseArtifactID + ' where TYPE = 3 and InRepository = 1)'
IF (select BR_sqlServerID from #BRFindSizes where UpdateCompleted = '2') = 1015083
Begin
update #BRFindSizes
set BR_ProductionSize = @sql2
where UpdateCompleted = '2'
end