Loop through all the rows of a temp table and call a stored procedure for each row
you could use a cursor:
DECLARE @id int
DECLARE @pass varchar(100)
DECLARE cur CURSOR FOR SELECT Id, Password FROM @temp
OPEN cur
FETCH NEXT FROM cur INTO @id, @pass
WHILE @@FETCH_STATUS = 0 BEGIN
EXEC mysp @id, @pass ... -- call your sp here
FETCH NEXT FROM cur INTO @id, @pass
END
CLOSE cur
DEALLOCATE cur
storing multi row stored procedure data to loop through rows later in c#
assuming that yor conf is an instance of Conf class, you just have to create a List to store data:
public List<Conf> GetData()
{
.....your code
var list = new List<Conf>();
SqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
var conf=new Conf();
conf.T_id = dr["t_id"].ToString();
conf.Cm_firstname = dr["cm_firstname"].ToString();
conf.Cm_lastname = dr["cm_lastname"].ToString();
conf.Cm_userid = Convert.ToInt32(dr["cm_userid"]);
conf.AgeOfNotification = dr["AGEOFNOTIFICATION"].ToString();
conf.DelegateSystem = dr["DELEGATESYSTEM"].ToString();
conf.P_Id = Convert.ToInt32(dr["P_id"]);
list.Add(conf);
}
dr.Close();
......
return list; // for the future use
}
you can use it like this
var list=GetData();
Executing a stored procedure on every row in a SQL Server Table
Did you ever try FUNCTION, you can calculate the work days in between two days in your FUNCTION.
SELECT *, dbo.fn_WorkDaysLate (startDate, endDate) AS DaysLate FROM dbo.vQualityControl
--OR
UPDATE A
SET A.DaysLate = dbo.fn_WorkDaysLate (A.startDate, A.endDate)
FROM dbo.vQualityControl A
Related Topics
Find All Parent Records Where All Child Records Have a Given Value (But Not Just Some Child Records)
How to Use Return Value of Insert...Returning in Another Insert
Error:More Than One Row Returned by a Subquery Used as an Expression
Alternative to Row_Number() to Get Row Position
Select Ids from Multiple Rows Where Column Values Satisfy One Condition But Not Another
How to Select Rows With Only Numeric Characters in Oracle SQL
Sql to Find Upper Case Words from a Column
Mysql - How to Use Like on Multiple Columns
Max and Min Sal With Employee Name in One Query
Select Rows Within Last Complete Minute
List All Employee'S Names and Their Managers by Manager Name Using an Inner Join
Counting the Number of Rows Returned by Stored Procedure
Convert Varchar Mmddyyyy to Mm/Dd/Yyyy Datetime and Select the Most Recent Date Only
Mysql Select Rows on First Occurrence of Each Unique Value
Postgresql How to Insert a Value With Double Quotes Inside Double Quotes
Oracle SQL Get the First and Last Records from an Ordered Dataset
Sql Query to Get the Employee Name and Their Manager Name from the Same Table