From: sam on
I have a UDF say Which is caluculating salary of an employee by using
Cusror.
Now i m using that UDF in a View in which i m passing it Id for a
value in view.
That's working fine if no of records are say around 1000 but if No are
Increasing then View is working very slow
Because foreach row in view that function is executing and Output is
produced

I have Searched for solution I Find an way to use Option(Recompile)
but don't know how to use with UDF.
Any Other Suggestion to Improve performance of view will bw welcomed

Thanx
From: Dave Ballantyne on
The simple answer is dont use Scalar UDFS

I give an example and your options on my blog here :
http://sqlblogcasts.com/blogs/sqlandthelike/archive/2009/10/15/udf-overhead-a-simple-example.aspx

I would imagine that the cursor inside the UDF is also not needed.

Post your full code for further advice


Dave Ballantyne
http://sqlblogcasts.com/blogs/sqlandthelike/

sam wrote:
> I have a UDF say Which is caluculating salary of an employee by using
> Cusror.
> Now i m using that UDF in a View in which i m passing it Id for a
> value in view.
> That's working fine if no of records are say around 1000 but if No are
> Increasing then View is working very slow
> Because foreach row in view that function is executing and Output is
> produced
>
> I have Searched for solution I Find an way to use Option(Recompile)
> but don't know how to use with UDF.
> Any Other Suggestion to Improve performance of view will bw welcomed
>
> Thanx
From: Uri Dimant on
sam
In addtion , perhaps if you show us DDL+ sample data + an expected result
we can advise you to writye the query without using a cursor

"sam" <sumesh.jangra2009(a)gmail.com> wrote in message
news:f6026ee0-b11c-4e4e-9ece-81ebfd5304c4(a)s36g2000prh.googlegroups.com...
>I have a UDF say Which is caluculating salary of an employee by using
> Cusror.
> Now i m using that UDF in a View in which i m passing it Id for a
> value in view.
> That's working fine if no of records are say around 1000 but if No are
> Increasing then View is working very slow
> Because foreach row in view that function is executing and Output is
> produced
>
> I have Searched for solution I Find an way to use Option(Recompile)
> but don't know how to use with UDF.
> Any Other Suggestion to Improve performance of view will bw welcomed
>
> Thanx


From: Plamen Ratchev on
You can see if you can rewrite the scalar UDF to table valued UDF. See example here:
http://sqlblog.com/blogs/alexander_kuznetsov/archive/2008/05/23/reuse-your-code-with-cross-apply.aspx

Or you can avoid the function at all if possible.

--
Plamen Ratchev
http://www.SQLStudio.com