SQL Server 2005 Question:
I\'m working on a data conversion project where I\'m taking 80k+ rows and moving them from one table to another. When I run the TSQL, it bo
Not exactly a cursor, but as effective - I had over 4 million rows to examine with multiple conversion failrues. Here is what I used, and it resulted in a two temp tables one with all my values and assigned rows and one that simply contained a list of rows in the first temp table that failed to convert.
select row_number() over (order by TimeID) as rownum,timeID into #TestingTable from MyTableWithBadData
set nocount on
declare @row as int
declare @last as int
set @row=0
select @last = count(*) from #TestingTable
declare @timeid as decimal(24,0)
create table #fails (rownum int)
while @row<=@last
begin
Begin Try
select @timeid=cast(timeID as decimal(24,0)) from #TestingTable where rownum = @row
end try
begin catch
print cast(@row as varchar(25)) + ' : failed'
insert into #fails(rownum) values(@row)
end catch
set @row = @row+1
end