Arizona1911
Arizona1911

Reputation: 2201

Execute function multiple times without using a loop

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)

Upvotes: 1

Views: 3627

Answers (3)

Eric J. Price
Eric J. Price

Reputation: 2785

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

Upvotes: 6

LukeHennerley
LukeHennerley

Reputation: 6434

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

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269583

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.

Upvotes: 2

Related Questions