First fix the first problem:
Quote:
Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query."
I did this like this:
SET @Oldlogo = convert(varbinary,'some binary code')
The problem you quote in your question is caused by :
SET @query = @query + ' IF EXISTS(SELECT 1 FROM Company WHERE CONVERT(varbinary,Company_Logo_TopLeft) = CONVERT(varbinary,''' + @Oldlogo + ''')) '
It is not clear why you are trying to insert 'some binary code' and convert it to varbinary again.
Once you've sorted out what you are actually trying to do, replace
EXEC (@query)
with
PRINT @query
until you are completely happy that the SQL you are generating is correct.
It's a good idea to start with a specific set of data and do raw SQL statements so that you can work out how to build the dynamic SQL - i.e. don't just dive straight in