tags:

views:

44

answers:

1

Hi I have a situation where given a Column "TotalDue" and a Percentage(17,5%)Could be anything.I need to deduct the percentage and put results in a table

CREATE TABLE #ResultTable (NettAmount money, GrossAmount money)

For example sake lets take AdventureWorks database they have a totalDue Column on

SELECT TotalDue from Sales.SalesOrderHeader

How Can I populate my TemporaryTable?

+1  A: 

UPDATE: Further to comment below

You may want to use the INSERT INTO ... SELECT syntax:

INSERT INTO #ResultTable 
            (NettAmount, GrossAmount)
SELECT      (TotalDue * (100 / 117.5)), TotalDue
FROM        Sales.SalesOrderHeader

I'm not sure if I correctly understood your table structure, but you may want to try something like the following:

UPDATE  #ResultTable
SET     NettAmount = GrossAmount * (100 / 117.5)

... where if GrossAmount is $117.50, the NettAmount will be set to $100.00.

Daniel Vassallo
Thanks for your reply.May be my question was not clear enough."Given a table Eg Sales.SalesOrderHeader in AdventureWorks" for example Get the TotalDue and create another table Eg #ResultTable with 2 Columns NettAmount and GrossAmount.
@devnet247: Will the `TotalDue` be the `GrossAmount` in the new table?
Daniel Vassallo
yes TotalDue will be GrossAmount in new table.INSERT INTO [dbo.ResultTable](NettAmount,GrossAmount)Select ?? FROMSales.SalesOrder
@devnet247: Updated my answer.
Daniel Vassallo
Thank you that works.A bit rusty on the old sql too much c#