This code block insert temp table returns all inserted rows
declare @comanyId bigint declare @memberId int declare @companyName nvarchar(50) declare @companyUrlName nvarchar(50) declare @email nvarchar(50) declare @membername nvarchar(50) create table #Temp ( CompanyId bigint, CompanyName Varchar(50), CompanyUrlName Varchar(50), Email Varchar(50), MemberName Varchar(50) ) declare crs_title cursor for select Id,companyName,CompanyUrlName from Company open crs_title fetch next from crs_title into @comanyId, @companyName,@companyUrlName while @@FETCH_STATUS =0 begin select top 1 @memberId=memberId from membercompany where companyId=@comanyId order by RoleId select @membername=[Name],@email=Email from Member where Id=@memberId Insert into #Temp select @comanyId,@companyName,@companyUrlName, @email,@membername fetch next from crs_title into @comanyId, @companyName,@companyUrlName end close crs_title deallocate crs_title select * from #Temp
Comments