• Rather than populate a variable with a subquery, use a simpler subquery directly inside the IN value list position, like this:

    select * from scpcommandeventlog where messageid = 3 and param1 in (select itemid from dbo.ItemList where sortid like @sortid)