473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calculated fields...

If I have a calculated field that returns a value from a udf, does that
field get calculated even when it's not being used in a Select statement? I
knw that if a calculated field's formula is based on fields in the same
record that the calculation is only performed when one of the two fields is
updated. But if I'm calling a UDF, there's no way for SQL Server to know
when to update the calculation. (In this case, the UDF does a count of
records in a child table based on criteria - not an aggregate) Of course if
the calculated field is in a select statement, it will be refreshed. But
what if I'm not calling that field in a query? Is it recalculated? The
bottom line is: How much overhead is there when I use a calculated field to
call a UDF?

Thanks.

--
Matthew.Wells
Ma***********@FirstByte.net
Aug 29 '08 #1
3 4263
Computed columns are virtual columns that are not physically stored in
the table (they get recalculated when you query the table), unless the
column is marked PERSISTED. The expression defining the computed column
must be deterministic when PERSISTED is specified.

There is an overhead associated with recalculating the computed value,
and it depends on how complex is the calculation. Persisting a computed
column is useful if you will be querying on that column a lot and use it
as filter, then you can index the computed column.

--
Plamen Ratchev
http://www.SQLStudio.com
Aug 29 '08 #2
That much I got, but does the computed column get computed if it's not part
of a SELECT statement?

"Plamen Ratchev" <Pl****@SQLStudio.comwrote in message
news:Hb******************************@speakeasy.ne t...
Computed columns are virtual columns that are not physically stored in the
table (they get recalculated when you query the table), unless the column
is marked PERSISTED. The expression defining the computed column must be
deterministic when PERSISTED is specified.

There is an overhead associated with recalculating the computed value, and
it depends on how complex is the calculation. Persisting a computed column
is useful if you will be querying on that column a lot and use it as
filter, then you can index the computed column.

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

Aug 29 '08 #3
No, it will not be computed until you query the column. It is very much
like defining a column based on calculation in a view.

--
Plamen Ratchev
http://www.SQLStudio.com
Aug 29 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anonymous | last post by:
Hi all, I have a form people use to enter checking data. One of the fields is calculated based on finding the difference of two input fields on the form. Here are the fields: CheckAmount...
1
by: Miguelito Bain | last post by:
hi everybody. i'm trying to find out what you can and can't do with/in calculated fields. any help, pointers, and/or advice would be greatly appreciated. i'm a newbie, but i want to learn, and...
5
by: John Bahran | last post by:
I am trying to use calculated fields in my query but all the results are zero ven when they're not. Please help. Thanks.
2
by: david | last post by:
Hi, I have a form with a couple of calculated fields. I want to put some code into the 'Form-Load' event to set various object states on the form, depending on the value of these fields. The...
2
by: Ryker | last post by:
I have a Purchase Order where I have a calculated field called Price that is calculated by multiplying Qty * Sales Price. I have 10 of these fields...Price 1 - Price 10 (for each line of the PO). ...
2
by: Olveres | last post by:
Hi, I have managed to work out how to add new lines into a calculated text box. However in this text box some of the outcome fields are empty however when previewing the report it includes the...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
2
by: mkbrady | last post by:
I have a query that includes calculated fields that generate numeric results. I have wrapped conversion functions CLng() and CDdl() around the calculated fields to ensure the data types are...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.