Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help with Store Proc

Author  Topic 

ssunny
Posting Yak Master

133 Posts

Posted - 2012-09-19 : 16:20:42
Hello Guys,

I am looking for a way to rewrite following store procedure using CTE or any other better solution.


CREATE PROCEDURE dbo.getrecords
as
begin
declare @tid int
create table #testtable (tid int, ttext varchar(300))

declare tcursor cursor for select tid from test
open tcursor
fetch tcursor into @tid
while @@fetch_status = 0
begin
insert into #testtable (tid, ttext) exec ('dbo.some_store_proc ' + @tid )
fetch tcursor into @tid
end
close tcursor
deallocate tcursor


SELECT
a,
b,
c
FROM test t (nolock)
join #testtable t1 on t1.tid = t.tid

END

drop table #testtable
go


Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-19 : 16:24:05
We'll need to see the code for "some_store_proc".

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -