• These wouldn't work in your context:

    [' + @SN + '].msdb.dbo.sysjobhistory h

    Anything inside brackets it takes as a literal name. Here, it thinks the server you're trying to access is called [' + @SN + ']. I can't think of a way where you can make the server name here dynamic without making the entire query dynamic.

    As a warning, every time you write dynamic code, you're opening yourself up for SQL Injection.