![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? |
#3
| |||
| |||
|
|
Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? Thanks a lot. |
#4
| |||
| |||
|
|
In the SP, 1) Update the columns in the table that need to be updated, and then 2) Select the updated values from the table to be returned to the client. "Andrew" wrote: Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? Thanks a lot. |
#5
| |||
| |||
|
|
SELECT A.ColA * B.ColB As Result FROM tableA As A INNER JOIN tableB As B ON A.ID = B.ID |
|
Andrew wrote: Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Create one query that returns the results of the calculations in the result set. E.g.: SELECT A.ColA * B.ColB As Result FROM tableA As A INNER JOIN tableB As B ON A.ID = B.ID WHERE < criteria -- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA) -----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv iQA/AwUBQmVSDoechKqOuFEgEQIbkwCff49oHcM1n6LQJUbBfyTKZv uE7zUAoOYO 0GSmwyaPYPrgZLpipCKOwrnT =VTo8 -----END PGP SIGNATURE----- |
#6
| |||
| |||
|
|
Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? Thanks a lot. |
#7
| |||
| |||
|
|
=?Utf-8?B?QW5kcmV3?= <Andrew (AT) discussions (DOT) microsoft.com> wrote in news:912F17CC-E359-457E-B2F3-6F15DE06034D (AT) microsoft (DOT) com: Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? Thanks a lot. How about using the query to populate a local temporary table (##TableName), and then modifiying the values as necessary before selecting them from the temp table to return to the user? -- Rumble "Write something worth reading, or do something worth writing." -- Benjamin Franklin |
#8
| |||
| |||
|
|
those columns can not be updated. Although updated value need to be returned, the original values must be kept. "CBretana" wrote: In the SP, 1) Update the columns in the table that need to be updated, and then 2) Select the updated values from the table to be returned to the client. "Andrew" wrote: Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? Thanks a lot. |
#9
| |||
| |||
|
|
#tempTableName is another way. What else? "Rumbledor" wrote: =?Utf-8?B?QW5kcmV3?= <Andrew (AT) discussions (DOT) microsoft.com> wrote in news:912F17CC-E359-457E-B2F3-6F15DE06034D (AT) microsoft (DOT) com: Hi, friends, I need to write a stored procedure to return records selected from 2 tables. However, before returning those records, values of some fields need to be recaculated with up-to-date data in some other tables of the same database, and the original field values in that 2 tables should keep the same. In another word, sp returned record values are not the values in db tables, but recalculated ones, and their original values should not be updated. So far I have two ways to do it: (1) In sp, create a view with values in the 2 tables, update values, return updated records, drop the view; (2) Create a table in db especially for this purpose, say volatileTable. Then, in sp, delete all records first, insert new records with values from 2 tables, update values, return updated records. I am not sure which one is better, and any other better approaches? Thanks a lot. How about using the query to populate a local temporary table (##TableName), and then modifiying the values as necessary before selecting them from the temp table to return to the user? -- Rumble "Write something worth reading, or do something worth writing." -- Benjamin Franklin |
![]() |
| Thread Tools | |
| Display Modes | |
| |