Declare @RawData table
(
SalesRep char(20),
SalesID char(2),
Load_Year int,
SALES decimal(18,2),
COST decimal(18,2)
)
Declare @RawData2 table
(
SalesRep char(20),
SalesID char(2),
YTD_SALES decimal(18, 2),
YTD_COST decimal(18, 2),
YTD_BM float,
SalesPrev decimal(18, 2),
CostPrev decimal(18, 2),
BMPrev float,
SalesPrev2 decimal(18, 2),
CostPrev2 decimal(18, 2),
BMPrev2 float,
BranchSalesPercent float
)

I need to get a % of total sales.

so in one memory table i have the total number

then in another table i have all the sales the people have made.

So i need a

select 1-(a.ytd_cost*1.00/b.sales)
from @rawdata b and @rawdata2 a <---not sure how to join them correctly

but I dont think I am doing it correctly :\ Any suggestions?

**View Complete Post**

## Export Visio Database Table Names to Excel