Monday, February 20, 2012

Newbee needs help

Hi,
I have the following statement:
select
dbo.udfCustomerName(CustomerID)
, Count(*)
from
Orders
group by
CustomerID
If Orders table has 1 million rows, does udfCustomerName get executed 1
million times?
Or does SQL server do the grouping in CustomerID first then call udf
function?
How can I be sure? I tried to use Print @.CustomerID inside udfCustomerName,
but SQL server rejected.
TIAIt does the grouping first. You can check the query plan and see that the
function is activated in the last step.
Adi
"Raymond Du" <rdrd@.yahoo.com> wrote in message
news:%23WnqpdKdGHA.1204@.TK2MSFTNGP02.phx.gbl...
> Hi,
> I have the following statement:
> select
> dbo.udfCustomerName(CustomerID)
> , Count(*)
> from
> Orders
> group by
> CustomerID
> If Orders table has 1 million rows, does udfCustomerName get executed 1
> million times?
> Or does SQL server do the grouping in CustomerID first then call udf
> function?
> How can I be sure? I tried to use Print @.CustomerID inside
> udfCustomerName, but SQL server rejected.
> TIA
>

No comments:

Post a Comment