troubleshooting Question

What is the best way to return multiple values from a function call that has several parameters?

Avatar of jadametz
jadametz asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
4 Comments1 Solution198 ViewsLast Modified:
Hello experts!

This question may have been answered before, but I cannot seem to find exactly what I am looking for.

I am going to simplify this question down to two dimesions from 3, but I think the answer for the 2 dimesional case should apply directly to the 3 dimensional one.

If I have a table with X,Y values in it, and I have a function ROTATE(@X float, @Y float) which rotates the X,Y point to a new coordinate system and returns a table (Range as float, Angle as float), what is the best (most efficient way) to write a query which will present the input values for each row in my table along with the rotated values for each row?

I think that a select statement that looks like this:
SELECT t.X,t.Y, (SELECT RANGE from ROTATE(t.X,t.Y)) as Range, (SELECT Angle from ROTATE(t.X,t.Y)) as Range From Table as t;
will do the trick, however as you can see, it needs to call the ROTATE function twice to get the job done; and in a 3 dimesional case, this calculation is pretty expensive.

Is there anyway to only make the call once for each record in the Table?

Thanks for the help!

ASKER CERTIFIED SOLUTION
dqmq

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros