select * from table where (m=@minuto or m='*') and (h=@ora or h='*') and (dow=@dow or dow='*') and (dom=@dom or dom='*') and (mon=@mese or mon='*')