April 8, 2010 at 7:55 am
Suppose I have a function that performs some mathematical operation on the input parameter x and returns a value y:
select dbo.MyMathFunc(10)
Is there a way to apply the function to the results of a select such as:
select dbo.MyMathFunc(select MyInt from MyTable)
Maybe I just can't come up with the correct syntax.
April 8, 2010 at 8:06 am
nano2nd (4/8/2010)
Suppose I have a function that performs some mathematical operation on the input parameter x and returns a value y:select dbo.MyMathFunc(10)
Is there a way to apply the function to the results of a select such as:
select dbo.MyMathFunc(select MyInt from MyTable)
Maybe I just can't come up with the correct syntax.
This?
declare @MyVariable as int;
select @MyVariable = MyInt from dbo.MyTable; -- where this returns one row or the last value from multiple rows
select dbo.MyMathFunc(@MyVariable);
April 8, 2010 at 8:15 am
Thanks, it worked as you expected. It applies the function to the first row returned from the select. How do I apply it iteratively to each of the rows in the table?
April 8, 2010 at 8:17 am
nano2nd (4/8/2010)
Thanks, it worked as you expected. It applies the function to the first row returned from the select. How do I apply it iteratively to each of the rows in the table?
That is what you asked for initially. Try this:
select dbo.MyMathFunc(MyInt) from dbo.MyTable;
April 8, 2010 at 8:24 am
Thanks, that did it. I really appreciate the help.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply