1

I have a simple table with IDs:

ObjectId
----------
100
101
102

I'd would like to execute a function fn_GetStuff(Id) multiple times like this:

fn_GetStuff(100)
fn_GetStuff(101)
fn_GetStuff(102)

Is it possible to do this without using a loop?

I tried this it doesn't work:

SELECT *
FROM myTable
INNER JOIN fn_GetStuff(myTable.ObjectId)
3
  • 1
    You need to put the schema in front of the function. This is a requirement. There are two types of answers below, one is for scalar functions and the other is for in-line table valued functions. One of them is right, but make sure to append the schema in all cases. Commented Mar 20, 2013 at 15:35
  • 2
    Is this a table-valued function? Commented Mar 20, 2013 at 15:38
  • Yes its a table-valued function. Commented Mar 20, 2013 at 15:40

3 Answers 3

6

OP is using a in-line table valued function it looks like so they would need a CROSS APPLY...

Select  *
From    myTable mt
Cross   Apply schema.fn_GetStuff(mt.ObjectID) f
Sign up to request clarification or add additional context in comments.

Comments

2

Assuming your function is a scalar-valued function, you can just do:

select fn_GetStuff(Objectid)
from myTable

If your function is table valued, then you would need to use cross apply.

Comments

0

You don't need to join because there isn't another table. You should be okay to do this:

SELECT fn_GetSTuff(t.ObjectId)
FROM myTable t

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.