Connecting Tech Pros Worldwide Help | Site Map

sql squeries

  #1  
Old August 20th, 2008, 10:55 AM
mo/-/sin
Guest
 
Posts: n/a
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.............
  #2  
Old August 20th, 2008, 12:15 PM
Andrew Morton
Guest
 
Posts: n/a

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


  #3  
Old August 20th, 2008, 01:35 PM
Plamen Ratchev
Guest
 
Posts: n/a

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
  #4  
Old August 20th, 2008, 01:35 PM
Plamen Ratchev
Guest
 
Posts: n/a

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
  #5  
Old August 20th, 2008, 06:05 PM
mo/-/sin
Guest
 
Posts: n/a

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...........
  #6  
Old August 20th, 2008, 09:05 PM
Plamen Ratchev
Guest
 
Posts: n/a

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
Closed Thread