C# 对存储过程中返回的结果运行foreach循环。

C# 对存储过程中返回的结果运行foreach循环。,c#,sql,sql-server,stored-procedures,C#,Sql,Sql Server,Stored Procedures,我有一个从表1返回结果的存储过程,然后在另一个存储过程中使用该结果来更新表2。我想知道是否可以将其合并到一个存储过程中,问题是需要基于表1中的值在表2上运行foreach循环,以查找所有要更新的值。不知道从哪里开始,也不知道是否可能 这是为每个项目运行某些内容的示例。但对于更新,您不应该需要这个,您应该能够通过交叉连接来解决这个问题,无论如何,下面的示例就是这样 declare @i int; set @i = 0; declare @t table ( int id identity, va

我有一个从表1返回结果的存储过程,然后在另一个存储过程中使用该结果来更新表2。我想知道是否可以将其合并到一个存储过程中,问题是需要基于表1中的值在表2上运行foreach循环,以查找所有要更新的值。不知道从哪里开始,也不知道是否可能

这是为每个项目运行某些内容的示例。但对于更新,您不应该需要这个,您应该能够通过交叉连接来解决这个问题,无论如何,下面的示例就是这样

 declare @i int;
set @i = 0;
declare @t table
(
int id identity,
varchar(max) col1,
varchar(max) col2
)

insert into @t(col1,col2)
select col1,
        col2 from  FROM        [Table]


set i = 0;
declare @sum int
set @sum = 0;
while(i < select count(*) from @t)
begin 
 select case when (col1 == col2) then @sum = @sum+1 else @sum from @t
where id = i;
i++;
end