Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 call a function for all the rows in a table

Author  Topic 

uv2944875
Starting Member

5 Posts

Posted - 2012-11-14 : 10:59:17
I have tables Teachers(tid int, teacherName varchar(20)) and Lectures(lid int, tid int, lectureName varchar(20)). This is a simplified version of my tables.

A scalar function f(tid int) returns the number of lectures for a teacher. I want to call this function for each teacher in Teachers.

Is it possible to implement this without a cursor (in which I place all the teachers and then call the function for each row)?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-14 : 11:00:39
You can use APPLY or just select

Select <columns>
,dbo.f(TID) as leactures
From Teachers


Jim
Everyday I learn something that somebody else already knew
Go to Top of Page

uv2944875
Starting Member

5 Posts

Posted - 2012-11-14 : 11:12:07
Cool, thanks.
quote:
Originally posted by jimf

You can use APPLY or just select

Select <columns>
,dbo.f(TID) as leactures
From Teachers


Jim
Everyday I learn something that somebody else already knew

Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-14 : 11:13:14
You're Welcome.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -