Consider the table SAMPLE:
id integer
name nvarchar(10)
There is a stored proc called myproc
. It takes only one para
I just declare the temporary table @sample and insert the all rows which have the name='rahul' and also take the status column to check that the row is iterated.and using while loop i iterate through the all rows of temporary table @sample which have all the ids of name='rahul'
use dumme
Declare @Name nvarchar(50)
set @Name='Rahul'
DECLARE @sample table (
ID int,
Status varchar(500)
)
insert into @sample (ID,status) select ID,0 from sample where sample=@name
while ((select count(Id) from @sample where status=0 )>0)
begin
select top 1 Id from @sample where status=0 order by Id
update @sample set status=1 where Id=(select top 1 Id from @sample where status=0 order by Id)
end