Now i am inserting data into table A from table B. here is a sample dynamic sql which insert data into #TmpZacksCons table from #TmpAll_Broker_LI
SET @sql='Insert Into #TmpZacksCons (Section, LineItem,Ord,
'+@PeriodCols+'
)
Select b.Section, b.LineItem,Max(Ord)+1 Ord,
'+@AvgSql+'
From #TmpAll_Broker_LI b
Group By b.Section, b.LineItem'
EXEC(@sql)
Now my requirement is bit change. i want to select a table which has many records and each records has type. one is average and other is Median.
i want to select from TableA and check if records type is average then select data from #TmpAll_Broker_LI
if records type is Median then select records from #TmpAll_Broker_LI_Median
so in my above sql i will select and check record type if Median then select data from #TmpAll_Broker_LI_Median else if record type id Average then select data from #TmpAll_Broker_LI
so tell me how could i compose this dynamic sql where based on records type data will be fetched from different table and that data will be inserted in #TmpZacksCons dynamic table.
please guide me with sample sql. thanks
Edit
My requirement is.
for each insert into TmpZacksCons i want to check what is the value of Type from Table3. if value is Average then select data from table2 and insert into TmpZacksCons and if type is Median then select data from table3 and insert into TmpZacksCons table. please give me the code accordingly with a sample code.
Thanks