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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 call a function for all the rows in a table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

uv2944875
Starting Member

5 Posts

Posted - 11/14/2012 :  10:59:17  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 11/14/2012 :  11:00:39  Show Profile  Reply with Quote
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

Edited by - jimf on 11/14/2012 11:02:07
Go to Top of Page

uv2944875
Starting Member

5 Posts

Posted - 11/14/2012 :  11:12:07  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 11/14/2012 :  11:13:14  Show Profile  Reply with Quote
You're Welcome.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000