Fixed query to use visitid as a parameter properly