I have sql stored procedure which pass and return some values:
CREATE PROCEDURE [dbo].[GetMoney]
@userId int,
@month DateTime
AS
BEGIN
....
Select @something
END
I want to call GetMoney procedure for each user in users table and use results in sql query. How can i do it?
The whole purpose of a RDBMS is that they operate in sets. Instead of going per user process all the users in 1 shot, it will be many times faster
if you really want to go the row based route, load all the users in a cursor and the loop over the cursor and call the proc for each user…but doing that you are using the database like a magnetic tape file…databases operate in SETS use a set based solution