-1

I am a Database beginner. I am using Microsoft SQL Server Management Studio. I am multiplying two columns of one table and assign the output of those columns to another table, but I don't know how to do that. Is there anyone to help me?

I have two columns one is UnitPrice column and the other is Quantity in PurchasesTable and I want to insert the output of these columns to TotalAmount of another table with the Name Dues. Thanks in advance.

Thom A
  • 88,727
  • 11
  • 45
  • 75
thenativeguy
  • 25
  • 1
  • 8
  • 1
    Pls, provide sample data and expected outcome (use the tabular format). Also, show us what you have tried. – DxTx May 09 '18 at 09:56
  • This sounds like quite a simple task. You're a beginner, but i suggest looking up the basics first, before asking people how to do it on a Q&A website. What your looking for is here is [`INSERT`](https://learn.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql?view=sql-server-2017), and the multiplication symbol in SQL Server (as it is in almost every computer language) is the asterisk (`*`). – Thom A May 09 '18 at 09:58

1 Answers1

0
/****** Object:  Table [dbo].[Sample1]    Script Date: 5/9/2018 3:59:09 PM 
******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Sample1](
[ID] [INT] IDENTITY(1,1) NOT NULL,
[UnitPrice] [DECIMAL](16, 2) NOT NULL,
[Quantity] [DECIMAL](10, 2) NOT NULL,
[TotalAmount]  AS ([UnitPrice]*[Quantity]),
CONSTRAINT [PK_Sample1] PRIMARY KEY CLUSTERED 
   (
   [ID] ASC
   )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = 
 OFF, 
 ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
 ) ON [PRIMARY]

  GO

INSERT INTO dbo.Sample1
    ( UnitPrice, Quantity )
VALUES  ( 100, -- UnitPrice - decimal
      25  -- Quantity - decimal
      )

SELECT * FROM dbo.Sample1
---OUTPUT------------
ID  UnitPrice   Quantity    TotalAmount
1   100.00  25.00   2500.0000
Sameer
  • 349
  • 4
  • 12