doubt on stored procedure

2 views
Skip to first unread message

viji

unread,
Oct 18, 2005, 3:08:45 AM10/18/05
to dotnetindia
hi friends,


while exists(select neospc_id from config_ghostsets
where setname= @sname)
begin
select @pc=neospc_id from config_ghostsets where
setname= @sname

if(@option = 1)
insert into pms_reboot_list(pc) values(@pc)

end

in this sp
select neospc_id from config_ghostsets where setname=
@sname
for this query i want to retrieve all the rows from
the data base
how to retrieve using loop in this sp itself...

in that @pc i want to retrieve all records... from
db.h can i do this

thanks,
viji.





__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com

Thread

unread,
Oct 18, 2005, 3:12:22 AM10/18/05
to .NetIndia
Hi Viji,

I think you have to use cursors for this. Lets wait for other
suggestions.

Regards
Thread

BabuLives

unread,
Oct 18, 2005, 4:40:55 AM10/18/05
to .NetIndia
Ya.. u can use cursor for that...
it goes like...

alter proc sppro
as
DECLARE @pc char(11)

Declare cur cursor for select * from t1 --put ur select query here

OPEN cur

FETCH NEXT FROM cur INTO @pc

WHILE @@FETCH_STATUS = 0
BEGIN

--put ur if loop logic here to insert
insert into t2 values(@pc)

FETCH NEXT FROM cur INTO @pc
END
CLOSE cur
DEALLOCATE cur
Go


i think am correct...

Is there any other simple way to do this????

Regards,
Satheesh

Raja Prakash

unread,
Oct 18, 2005, 5:10:14 AM10/18/05
to Techdot...@googlegroups.com
Hey guys.. i hope this is the only way to do loop and simplest one... and you should use it depending upon how much data you are looping because i consumes a lot of resource....
 
Thank you
Raja Prakash

 

Thread

unread,
Oct 18, 2005, 5:56:09 AM10/18/05
to .NetIndia
Yes this is the only way cos the problem here is we have to get all the
col values. and doing select @s=name from table will give only the last
value. Cursor is the only way to get all the values. Here the scenario
is simliar to an array..

Regards
Thread

Siva CH

unread,
Oct 18, 2005, 7:11:12 AM10/18/05
to Techdot...@googlegroups.com
Hi Vijii,
Using cursors is one option. The other option is to store the result of the query
 
select neospc_id from config_ghostsets where
setname= @sname
 
 in a temporary table/table variable and loop through it using WHILE, so that you can avoid cursors and gain good performance.
 
I hope this helps
 
Regards,
Siva

 

Ravi

unread,
Oct 18, 2005, 7:31:59 AM10/18/05
to Techdot...@googlegroups.com
yes i agree with him..........
 
regards,
ravi

BabuLives

unread,
Oct 18, 2005, 7:52:39 AM10/18/05
to .NetIndia
So this procedure is have greater performance than using cursor???


alter proc spprotemptable
as

Select col into temp# from t1 --put ur select query here

insert into t2 select * from temp# --put ur if loop logic here to
insert


drop table temp#

GO


Regards,
Satheesh

Reply all
Reply to author
Forward
0 new messages