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)
 Set base alternative of cursors?

Author  Topic 

musman
Starting Member

17 Posts

Posted - 2008-06-13 : 11:56:47
Hey all,
I am spinning my wheels to get this thing resolved unable to do that. How can i convert this code into set based or without cursors code.

declare cursor2 cursor for
select File_Name, File_Title_Txt, Upd_Mtch_tx, UpdateInd, AddInd, DeleteInd, AnyUpdateInd from File_Object_Table
where TableName = ''' + @Table + '''
and Criteria = ''' + @Criteria + '''
and File_Title_Txt = ''' + @Title + '''

declare @File_Name varchar(50)
declare @File_Var1 varchar(50)
declare @File_Var2 varchar(500)
declare @File_Var3 bit
declare @File_Var4 bit
declare @File_Var5e bit
declare @File_Var6 bit

open cursor2
fetch next from cursor2 into @File_Name, @File_Var1, @ExtraUpdateMatch, @PullUpdate, @File_Var4, @File_Var5e, @File_Var6

WHILE (@@fetch_status = 0)
begin

if @File_Var6 = 1
begin
exec (''INSERT ConfirmTable SELECT ''''' + @fileId + ''''', A.UnitNbr, ''''' + @Title + ''''', '' + @File_Var1 + '', A.'' + @File_Name + '', B.'' + @File_Name + '', ''''U''''
from #tempTable A left join #tempTable B on B.UnitNbr = A.UnitNbr and B.ActivityStatusCd = ''''U'''' '' + @File_Var2+ ''
where A.ActivityStatusCd = ''''O'''' and B.ActivityStatusCd = ''''U'''''')

end
fetch next from mtcursor2 into @File_Name, @File_Var1, @File_Var2, @File_Var3, @File_Var4, @File_Var5e, @File_Var6
end

close cursor2
deallocate cursor2

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-13 : 12:43:23
Can you explain what your requirement is with tables involved?
Go to Top of Page

musman
Starting Member

17 Posts

Posted - 2008-06-13 : 12:48:18
The parameters in Where are dynamic taking tablenameand criteria dynamically.
I am supposed to insert the data if condition matches. I hv tried it doing.
If (col_length(''Table'',''Col'') is not null) for every column and then trying exec(insert) but it doesnt work.
Go to Top of Page
   

- Advertisement -