sql squeries 
August 20th, 2008, 10:55 AM
| | | |
i want to make a table in sql server2005 with 3 columns the data type
of first two column is int.. i want that the value in column 1 should
be multiplied
by the value in column 2 and the total should appear in column 3.. is
it possible............. | 
August 20th, 2008, 12:15 PM
| | | | re: sql squeries
mo/-/sin wrote: Quote:
i want to make a table in sql server2005 with 3 columns the data type
of first two column is int.. i want that the value in column 1 should
be multiplied
by the value in column 2 and the total should appear in column 3.. is
it possible.............
| It sounds like you want a computed column, e.g. http://balajiramesh.wordpress.com/20...l-server-2005/
Andrew | 
August 20th, 2008, 01:35 PM
| | | | re: sql squeries
In addition to using a computed column, you can create a view to perform
the calculation and use the view as needed:
CREATE TABLE Foo (
keycol INT PRIMARY KEY,
col1 INT,
col2 INT);
INSERT INTO Foo VALUES(1, 3, 5);
GO
CREATE VIEW Bar (col1, col2, col3)
AS
SELECT col1, col2, col1 * col2
FROM Foo;
GO
SELECT col1, col2, col3
FROM Bar;
Plamen Ratchev http://www.SQLStudio.com | 
August 20th, 2008, 01:35 PM
| | | | re: sql squeries
Actually a better example for the view should have been:
CREATE VIEW Bar (keycol, col1, col2, col3)
AS
SELECT keycol, col1, col2, col1 * col2
FROM Foo;
Plamen Ratchev http://www.SQLStudio.com | 
August 20th, 2008, 06:05 PM
| | | | re: sql squeries
On Aug 20, 5:28*pm, Plamen Ratchev <Pla...@SQLStudio.comwrote: Quote:
In addition to using a computed column, you can create a view to perform
the calculation and use the view as needed:
>
CREATE TABLE Foo (
* keycol INT PRIMARY KEY,
* col1 INT,
* col2 INT);
>
INSERT INTO Foo VALUES(1, 3, 5);
>
GO
>
CREATE VIEW Bar (col1, col2, col3)
AS
SELECT col1, col2, col1 * col2
FROM Foo;
>
GO
>
SELECT col1, col2, col3
FROM Bar;
>
Plamen Ratchevhttp://www.SQLStudio.com
| buddy.. here you are passing three value i want that i shall insert
only two values and the product of the two values should appear in
third column.......
and moreover i m not talking about the select statement........... i
want to enter that value in the table........... | 
August 20th, 2008, 09:05 PM
| | | | re: sql squeries
Did you try the example? The insert statement has 3 values because it
inserts the key column too. The view will calculate col3 automatically.
Plamen Ratchev http://www.SQLStudio.com |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|