Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert a month that does not exist in the orig.table

Status
Not open for further replies.

fredong

IS-IT--Management
Sep 19, 2001
332
US
I have a table that contains columns SalesRep, customer, vendor, tranmonth, totalsale. I need to insert a month that does not exist under the SalesRep,customer,vendor. which I will place a totalsale value of 0. Tomake it clear Basically, I want to insert the month with the totalsale value 0 that the Salesperson have not sold to this customer under this vendor.

Thanks
 
If you create a table that has the twelve months Jan through Dec, you could do an outer join to the table and zero fill the NULLS
 
Can you illustrates a little bit more by showing an example thanks.
 
Table1 StaffID, Month, TotSales
Table2 Month

Select Table1.StaffID, Table2.Month, Table1.Totsales
From Table1
Left Outer Join
Table2
ON Table1.Month = Table2.Month;
 
I'm not sure I was quite right with that join, you could do the following.

Table1 StaffID, Month, TotSales
Table2 Month

Select AllComb.StaffID,
AllComb.Month,
Coalese(Table1.Totsales, 0)
From
(SELECT Table1.StaffID, Table2.Month) AllComb(ID,Month)
Left Outer Join
Table1
ON Table1.StaffID = AllComb.ID
AND Table1.Month = AllComb.Month
 
what is the "ALlComb" is that table2 or a function?


and what is the "ID" come from in the AllComb(ID,Month)?
Please advise.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top