Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it possible to get this desired output without using cursor.

Status
Not open for further replies.

mrpro

Programmer
Oct 11, 2004
64
GB
Hi
i have written a stored procedure using cursor.I know we should avoid using cursors whenever possible.I think this sp could be written without using cursor but have no clue. any help will be appreciable.

here is my original sp..hope this could explain the problem..

declare c1 cursor local for

select ResourceId from viewItems where viewId=@viewId

declare @id int
open c1
fetch next from c1 into @id
while @@fetch_status=0
begin
insert into ##temp (BookingId,Name,start,finish,Resource)
select BookingId,Name,start,finish,Resource from Bookings where ResourceId=@id

fetch next from c1 into @id
end

thanks
 
try

Code:
insert into ##temp (BookingId,Name,start,finish,Resource)
select BookingId,Name,start,finish,Resource from Bookings where ResourceId IN
(select ResourceId from viewItems where viewId=@viewId)



"I'm living so far beyond my income that we may almost be said to be living apart
 
gunshot..it is so simple but never thought of..

i found we could get the resultset without storing them to ##temp table as our select statement will do the job





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top