Python Forum
Insert into sublist if sublist is not having same no of records.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert into sublist if sublist is not having same no of records.
#7
From Database i am able to do it by adding Zeros , unable to do it in python.

Select * from #FactSalesQuota

SalesamountQuota	CalendarYear	Employeekey
28000.00	2010	272
308000.00	2011	272
582000.00	2012	272
387000.00	2013	272
367000.00	2010	281
3037000.00	2011	281
4822000.00	2012	281
2936000.00	2013	281
637000.00	2010	282
3440000.00	2011	282
478000.00	2010	296
1209000.00	2012	296
CREATE TABLE #CalendarSales_final (SalesamountQuota DECIMAL(20,4),CalendarYear INT,Employeekey INT)

SELECT  Distinct Identity(INT,1,1) Rid,EmployeeKey INTO #temp  FROM FactSalesQuota

SELECT  DISTINCT Calendaryear INTO #dates  FROM FactSalesQuota
DECLARE @i INT,@j INT=1,@Emp INT
SELECT  @i =Rid FROM #temp

WHILE @j<=@i 
Begin
SELECT  @emp=EmployeeKey FROM #temp where Rid=@j
INSERT INTO #CalendarSales_final
SELECT  ISNULL(C.salesamountQuota,0)SalesamountQuota, d.*,@emp FROM FactSalesQuota c Right join #Dates as d   ON c.Calendaryear=d.Calendaryear 
and EmployeeKey  in (SELECT  t. EmployeeKey FROM #temp as t WHERE Rid=@j)
Set @j=@j+1
end

SELECT  * FROM #CalendarSales_final 
Reply


Messages In This Thread
RE: Insert into sublist if sublist is not having same no of records. - by parthi1705 - May-16-2019, 11:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Use one list as search key for another list with sublist of list jc4d 4 2,221 Jan-11-2022, 12:10 PM
Last Post: jc4d
Question Sublist/ Subarray into string Python SantiagoPB 2 2,171 Apr-23-2021, 07:03 PM
Last Post: SantiagoPB
  List of objects with sublist medatib531 4 2,372 Mar-01-2020, 06:16 PM
Last Post: buran
  Split List and Sublist from Pyodbc parthi1705 1 2,259 May-05-2019, 10:44 AM
Last Post: Larz60+
  merging sublist into single list in python abhishek8singhai 8 9,609 Mar-22-2019, 11:46 PM
Last Post: micseydel
  Can I use a sublist as an argument in python? MartinBerlin 3 4,068 Aug-25-2018, 10:46 AM
Last Post: buran
  Insert using psycopg giving syntax error near "INSERT INTO" olgethorpe 4 15,736 Jul-21-2017, 07:39 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020