UPDATE A SET A.FDatabase = B.FDatabase FROM TClient AS A, ( SELECT FClientId,SUBSTRING(String,0,CHARINDEX(';',String)) AS FDatabase FROM ( SELECT FClientId,String = SUBSTRING(FConnectionString, CHARINDEX('Initial Catalog',FConnectionString) + LEN('Initial Catalog')+1,LEN(FConnectionString)) FROM TClient WHERE FServerId = 106 )AS T) AS B WHERE A.FClientId = B.FClientId