Scottish state bank records £138mn loss on back of failed investments