This is what I am trying to do EXEC sp1 1 SELECT * FROM x UNION if(@num <= 1) EXEC sp1(2) else null //want to return null to stop I could do this is with a programming language but I don't have an idea what is that I am doing wrong with programming in SQL? Continue reading...