First, check your select query with temp table whether it's giving your expected output or not. Then you try with Stored Procedure. Otherwise, send us the clear definition of your problem.
For more information, check the following link.
I think, it will be helpful for you.