sql - How to loop through stored procedure recordset? -


i have select statement

declare @t table (percentage float) declare @acc int  set @acc = 1 declare @max int  select @max = max(hireid) newhire while (@acc <= @max)     begin         if (@acc in (select hireid newhire))             begin try                 insert @t                   select                     cast((select count(*) hire_response hireid = @acc , (hireresponse = 0 or hireresponse = 1)) float) /                      cast((select count(*) hire_response hireid = @acc) float)             end try             begin catch                 insert @t                  select 0.0             end catch         set @acc = @acc + 1     end select * @t 

in code, looping through newhire records id, 1 highest one. realized not want anymore. have stored procedure called sp_selectnewhire2sql gets newhire table in specific way. want call it, , aquire returning recordset, , loop through top bottom.

note: doing loop id 1 highest wont work anymore, because order of id's mixed up.

is there way that?

thanks.

select     nh.hireid,     isnull(1e0 *           count(case when hireresponse in (0,1) hr.hireid end) /            nullif(count(hr.hireid), 0)        , 0) percentage     newhire nh     left join     hire_response hr on nh.hireid = hr.hireid group     nh.hireid 

note need include hireid in output. there no guaranteed order result set unless order used, can't assume list of percentages in order


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -