|I suspect there are more than 1 record matching your @code filter and you are trying to stuff more than 1 record into @Temp.
Nope - thats not it, you have top 1. It works for me on sql server 2008 R2. I used this
SET @Code = '103'
DECLARE @TEMP VARCHAR(7) =
(SELECT TOP 1 filename
WHERE LEFT(filename, 3) = @Code)
Which gives me the first 7 characters of the filename (all the file names start with 103). Changing @Code returns null
Never underestimate the power of human stupidity