Return value from stored procedure inside a select statment

Select statement with value from stored procedure.

We have product table where we return all product info and a stored procedure that return the correct price for the product. (PHP)

The problem is when we want to sort on the price returned from SP.

Any suggestion?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
Well you could create a temp table  (from the SP) and join that to the product table

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
myhrvoldAuthor Commented:
The SP return only one value the price for the product.

SELECT WEB_Prod.ProdNo ,WEB_Prod.Descr FROM [WEB_Prod]

For each row, we run SP_GetCustomerProductPrice 'PRODNO','CUSTNO'

The stored procedure is very complex, over 1000 lines.....
John TsioumprisSoftware & Systems EngineerCommented:
Well you could "enclose " the SP inside a While loop and feed the temp table.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

myhrvoldAuthor Commented:
Do you have any example code to pin me in right direction?
John TsioumprisSoftware & Systems EngineerCommented:
Take a look at Ms article
If still have issues let me know have to dig up my old sql files.
Scott PletcherSenior DBACommented:
The stored procedure is very complex, over 1000 lines.....

Yikes.  But you still need to convert the logic into an inline table-valued function if at all possible.  Then you can just CROSS APPLY to it, with great performance and its results become just another table in the query: you can sort on it, use WHERE on it, join on it, etc..
Aneesh RetnakaranDatabase AdministratorCommented:
You can modify the stored procedure, either to accept the list of ProdNo as input or you can join the  [WEB_Prod] table inside the stored procedure.
Between its not a good practice to name the storedprocedures with the prefix 'sp_'
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.