Check If Value Exists In Table
Your example looks quite simple and does not need sp_executesql statement (as long as your query returns only one row)...

You can set your variable in your select :

Create Table #Test1 (id int,name varchar(100))
Insert Into #Test1 Values (1, 'Blue'), (2, 'Red'), (3, 'Pink'), (4, 'Orange')

Declare @Color varchar(100), @returned_id varchar(100)
Set @Color = 'Pink'

Select @returned_id  = id 
from #Test1 
WHERE name = @Color

if @returned_id is null
    print 'Error - no rows returned for ' + @Color
else 
    print @returned_id

Drop Table #Test1