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 2005 Forums
 Transact-SQL (2005)
 Using set based query instead of cursor EXAMPLE

Author  Topic 

imranabdulaziz
Yak Posting Veteran

83 Posts

Posted - 2010-07-21 : 23:50:10
Dear All,
I am using sql server 2005.
I want to use Set based Query instead of Cursor for row wise transaction.
If anyone have any example on the same or useful like where the example are available, Please Post

Thank you

Sachin.Nand

2937 Posts

Posted - 2010-07-22 : 00:33:28
Can you yourself create a scenario where you think that there is no way except a Cursor to achieve the desired o/p.
Someone on this forum will surely help you with an equivalent set based approach.
Here is one from me.


declare @tbl table(col1 int,col2 int)
insert into @tbl
select 10 ,15
;with cte
as
(
select col1,col2,col1 as id from @tbl
union all
select t1.col2,t1.col1,cte.id+1 from @tbl t1
inner join cte on cte.id+1<=t1.col2
)
select * from cte




Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page
   

- Advertisement -