473,412 Members | 2,092 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,412 software developers and data experts.

Reference second table in computed column

Is it possible to include a related table in the computation of a column. For example, if I want to store the total of LINE.QTY on ORDER.QTY.

e.g. what is the correct way to express the following pseudo dode:

alter table ORDER
add QTY as sum(LINE.QTY) where line.order_id = order.id

All I can find on MSDN site is that I can't use a subquery.
Sep 18 '08 #1
7 2674
code green
1,726 Expert 1GB
You want to ADD a column to a table based on the result of a query.
Surely not. This makes no sense
Sep 18 '08 #2
I have a number of different applications (differing technologies) accessing the data. I want to have the ORDER.QTY available to all applications without them all having to calculate it independently.
Sep 18 '08 #3
code green
1,726 Expert 1GB
perfectly understandable.
But why add a new column to an existing table?
Sep 18 '08 #4
ORDER.ID
ORDER.CUSTOMER

LINE.ID
LINE.ORDER_ID (fk)
LINE.QTY

I want to simplify the instances of where users want to get one row back per ORDER which includes the summed QTY.

I know I could use a view, but they need update access to ORDER & there are aternate indices.
Sep 18 '08 #5
code green
1,726 Expert 1GB
You have chosen not to answer my question twice now.
I am also finding very difficult to follow your problem
I know I could use a view, but they need update access to ORDER & there are aternate indices.
Maybe you should rephrase the question.
Telling us the data you have and the result you are trying to achieve
Sep 19 '08 #6
jkmyoung
2,057 Expert 2GB
Why get hung up on the one point?
Technically he should divide the task into 2 parts.

1. Add a column. set everything to a default value, say 0. Only do this once.

2. Update this column in the table based on another value.

1 is easy, 2 is harder.
Sep 19 '08 #7
....
2. Update this column in the table based on another value.

1 is easy, 2 is harder.
I might have missed something, but 2 doesn't seem much harder to me.

If you create a trigger on the LINE table which updates the related ORDER row totals when ever the LINE values change / added / deleted ... piece of cake!

Personally, I don't do this unless I really need to optimize for speed, then I create a new column on the header table, with a prefix I know I don't edit (ussually 'agg_' for aggregate), and a default value, then create the trigger(s) for insert, update, & delete to keep the column up to date.

There is a cost, but if you are already optimizing, the pay off is probably worth it.

Good luck,
John
Sep 19 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: tperovic | last post by:
Using SS2K, I'm getting the following error while bulk inserting: Column 'warranty_expiration_date' cannot be modified because it is a computed column. Here is my bulk insert statement: ...
9
by: DMAC | last post by:
If i want to split a computed column into two or more columns based on the the length (its a varchar) of the computed column, how often will sql server determine what the computed column is?...
7
by: Wolfgang Kreuzer | last post by:
Hello all, I have two tables - Projects and ProjectStruct Table Projects contains master records of the projects, ProjectStruct allows to define a project herarchie and contains the fields...
0
by: Jim Heavey | last post by:
Hello, I have created a computed column which concatenates a name and date. My problem is that if the 10 is not 10 characters, I get an extra character placed into the computed column. Here is the...
10
by: krunom | last post by:
I write some application with asp.net (c#) and here is my problem. This code (with "commented" string line) works well: when i open this page in Internet Explorer i get in DataGrid2 some data frome...
7
by: slitvinov | last post by:
I am learning Relax NG. The problem is that I cannot figure out how to make a schema for a table. In my case I would like to make a table with any name of child elements (columns) but columns...
7
by: Aamir Mahmood | last post by:
Hi All I have DataTable object. Is there a way that I can know which fields (columns) in the table are computed. Apparantly the DataTable.Columns returns all columns both computed and other....
1
by: abinesh.agarwal | last post by:
Hi , I want to update the column in a table based on the updation of the other column in the same table, but not getting the desired result. DDL: CREATE TABLE .( NULL,
10
by: owuraku | last post by:
Hi y'all Can I reference a cell in an access table within a VBA code?? I have 1 x 2 table (1 row and 2 columns). The first column is just an autoID generator. The second column keeps track of dates....
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.