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 2000 Forums
 SQL Server Development (2000)
 User functions and performance

Author  Topic 

davidpardoe
Constraint Violating Yak Guru

324 Posts

Posted - 2001-06-19 : 10:39:16
Can anyone help me improve the performance of the following?

I have a table of circa 3 million records with about 30 fields I wish to convert from varchar fields to int fields (among 250 fields in total). At the moment I use the following user function to check for non numeric values, setting these to null before converting. This takes about 3 hours on our hardware set up compared to just 45 min to load the entire table from a text file. I am convinced that there is a quicker way to do this. Any thoughts?

CREATE FUNCTION convnum
( @field varchar(8000)
)
RETURNS int
AS
BEGIN
declare @fieldout int
select @fieldout=case when isnumeric(@field)=1 then cast(@field as int) else null end

RETURN (@fieldout)

END


   

- Advertisement -