sql server - SQL Function in column running slow -


i have computed column(function) causing 1 of tables extremely slow (its output column in table. thought might logical statements in function. commented out , returned string called 'test'. still caused table slow. believe select statement slowing down function. when comment out select statement, cherry. think not using functions in correct manner.

function [dbo].[pend_type](@suspense_id int, @loan_id nvarchar(10),@suspense_date datetime, @investor nvarchar(10)) returns nvarchar(20) begin declare @closing_date datetime, @paid_date datetime declare @pendtype nvarchar(20)  --this issue!!!! select @closing_date = date_closing, @paid_date = date_paid table loan_id = @loan_id  set @pendtype = 'test'  --commented out logic  return @pendtype end 

update:

i have computed column similar , column in same table. 1 runs fast. see difference in why be?

declare @yorn nvarchar(1) if((select count(suspense_id) table suspense_id = @suspenseid) = 0) set @yorn = 'n' else set @yorn = 'y' return @yorn 

you have isolated performance problem in select statement:

select top 1 @closing_date = date_closing, @paid_date = date_paid table loan_id = @loan_id; 

to make run faster, create composite index on table(load_id, date_closing, date_paid).

by way, using top no order by. when multiple rows match, can 1 of them back. normally, top used order by.

edit:

you can create index issuing following command:

create index idx_table_load_closing_paid on table(load_id, date_closing, date_paid); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -