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

sql squeries

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.............
Aug 20 '08 #1
5 1309
mo/-/sin wrote:
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
Aug 20 '08 #2
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
Aug 20 '08 #3
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
Aug 20 '08 #4
On Aug 20, 5:28*pm, Plamen Ratchev <Pla...@SQLStudio.comwrote:
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...........
Aug 20 '08 #5
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
Aug 20 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: manjava | last post by:
hello, i have this error Error: the xajax Javascript component could not be included. Perhaps the URL is incorrect? URL: /xampp/htdocs/xajax_js/xajax_core.js please can anyone help me see my...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.