Welcome to Dream.In.Code
Become an Expert!

Join 150,404 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 931 people online right now. Registration is fast and FREE... Join Now!




trigger or stored procedure

 
Reply to this topicStart new topic

trigger or stored procedure

blueletter
28 Mar, 2008 - 07:54 AM
Post #1

New D.I.C Head
*

Joined: 28 Nov, 2005
Posts: 22


My Contributions
I need to know how to multiply two columns in the same row to then place the product in the next field:

| CELL_1 | |CELL_2| |CELL_1 x CELL_2|

I was wondering if I would use a trigger or a stored procedure. I also cant really find and sample code that is even close to what I am talking about. so if you can post some or even links that would be much appreciated.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Trigger Or Stored Procedure
28 Mar, 2008 - 08:16 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You don't need either actually. This type of thing can be done using SQL itself.

CODE

Update tablename set column3 = (column1 * column2) where id = 1


This should set column3 to the product of column1 and column2 for the row specified by id 1. I hope that helps. smile.gif
User is offlineProfile CardPM
+Quote Post

blueletter
RE: Trigger Or Stored Procedure
28 Mar, 2008 - 08:24 AM
Post #3

New D.I.C Head
*

Joined: 28 Nov, 2005
Posts: 22


My Contributions
QUOTE(Martyr2 @ 28 Mar, 2008 - 09:16 AM) *

You don't need either actually. This type of thing can be done using SQL itself.

CODE

Update tablename set column3 = (column1 * column2) where id = 1


This should set column3 to the product of column1 and column2 for the row specified by id 1. I hope that helps. smile.gif



Thanks a lot man.
User is offlineProfile CardPM
+Quote Post

Trogdor
RE: Trigger Or Stored Procedure
30 Mar, 2008 - 04:52 AM
Post #4

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 549



Thanked: 4 times
Dream Kudos: 125
My Contributions
you can also remove column3 and emulate its existence with a view. that is much less errorprone, as its value will be calculated on the fly when you request the data.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:21PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month