• Let's start with the basics before we even look at the logic of your query:
    (1) Why are you passing in dates as varchar?  You only need two parameters here: one for the start date and one for the end date.  Make them both smalldatetime
    (2) What is the @type parameter for?  It's not used in the stored procedure
    (3) Why do you select everything into a temp table and then select straight back out?
    (4) Is this stored procedure in the POMDB database?

    We're probably going to need some DDL, sample data and expected results to sort this out.

    John