| Author |
Topic |
|
sateesh.sqldba
Starting Member
25 Posts |
Posted - 2010-07-22 : 00:15:57
|
| HI expertsALTER Proc [dbo ].[ic_Proc_IBA](@yr int, @qtr int, @mn int, @wk int, @Zone varchar(50), @Area varchar(50), @LCT varchar(50), @business varchar(50), @Modality varchar(50), @subMod varchar(50), @report_type varchar(50)) as Begin SET NOCOUNT ON if @report_type = 'Management' BEGINCreate table #temp_1 (yr numeric, mn numeric, zone varchar(100), cnt numeric)insert into #temp_1SELECT Yr Yr2, Mn Mn2, Zone COL1,SUM(sid) from(select Tm.Yr,Tm.Mn,RM.Zone, count(*) sid from ic IBA Inner Join ic_LCTMapping RM on IBA.LCT = RM.Center_Description Inner Join (Select distinct m.Mn_Id, m.mn, q.yr from C_Time_Wk w, C_Time_Mn m, C_Time_Qtr q Where q.qtr_id = m.qtr_id and q.yr_id = m.yr_id and q.qtr_id = w.qtr_id and q.yr_id = w.yr_id and w.mn_id = m.mn_id and w.yr_id = m.yr_id) Tm on IBA.Mn_Id = Tm.Mn_Id where Tm.Mn_Id between @mn_id - 11 and @mn_id and RM.Zone = isnull(@Zone, RM.Zone) and RM.LCT = isnull(@LCT, RM.LCT) Group by Tm.Yr,Tm.Mn,RM.Zone )y Group by Yr,Mn,Zone order by 3,1,2 Create table #temp_2 (yr numeric, mn numeric, zone varchar(100), cnt numeric)insert into #temp_2SELECT Yr Yr2, Mn Mn2, Zone COL1,SUM(sid) from(select Tm.Yr,Tm.Mn,RM.Zone, count(*) sid from ic_Defects IBA Inner Join ic_LCTMapping RM on IBA.LCT = RM.Center_Description Inner Join (Select distinct m.Mn_Id, m.mn, q.yr from C_Time_Wk w, C_Time_Mn m, C_Time_Qtr q Where q.qtr_id = m.qtr_id and q.yr_id = m.yr_id and q.qtr_id = w.qtr_id and q.yr_id = w.yr_id and w.mn_id = m.mn_id and w.yr_id = m.yr_id) Tm on IBA.Mn_Id = Tm.Mn_Id where Tm.Mn_Id between @mn_id - 11 and @mn_id and RM.Zone = isnull(@Zone, RM.Zone) and RM.LCT = isnull(@LCT, RM.LCT) Group by Tm.Yr,Tm.Mn,RM.Zone )y Group by Yr,Mn,Zone order by 3,1,2 Select a.Yr, a.Mn, a.Zone, cast(((1-(b.Cnt/ a.Cnt))*100) as numeric) from #temp_1 aleft outer join #temp_2 b on a.yr = b.yr and a.mn = b.mn and a.zone = b.zoneENDSET NOCOUNT offendthis query is working fine but we r using temp tables here with out that con't we make this main thing we could need to group yr,mn,Zone there is only on change in two temp tablescon't we?sateesh |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-07-22 : 00:21:46
|
| Please post some sample data & expected o/p.No on here has time to get into the logic of your code & then try to figure it out what you need.Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
sateesh.sqldba
Starting Member
25 Posts |
Posted - 2010-07-22 : 00:29:02
|
Hi expertsi have two tables one is IC and another one is IC_defects i need count of both tables two find out count(IC)/COUNT(IC_DEFECTS) there are some other columns like mn,yr,zone to display it quote: Originally posted by sateesh.sqldba ALTER Proc [dbo ].[ic_Proc_IBA](@yr int, @qtr int, @mn int, @wk int, @Zone varchar(50), @Area varchar(50), @LCT varchar(50), @business varchar(50), @Modality varchar(50), @subMod varchar(50), @report_type varchar(50)) as Begin SET NOCOUNT ON if @report_type = 'Management' BEGINCreate table #temp_1 (yr numeric, mn numeric, zone varchar(100), cnt numeric)insert into #temp_1SELECT Yr Yr2, Mn Mn2, Zone COL1,SUM(sid) from(select Tm.Yr,Tm.Mn,RM.Zone, count(*) sid from ic IBA Inner Join ic_LCTMapping RM on IBA.LCT = RM.Center_Description Inner Join (Select distinct m.Mn_Id, m.mn, q.yr from C_Time_Wk w, C_Time_Mn m, C_Time_Qtr q Where q.qtr_id = m.qtr_id and q.yr_id = m.yr_id and q.qtr_id = w.qtr_id and q.yr_id = w.yr_id and w.mn_id = m.mn_id and w.yr_id = m.yr_id) Tm on IBA.Mn_Id = Tm.Mn_Id where Tm.Mn_Id between @mn_id - 11 and @mn_id and RM.Zone = isnull(@Zone, RM.Zone) and RM.LCT = isnull(@LCT, RM.LCT) Group by Tm.Yr,Tm.Mn,RM.Zone )y Group by Yr,Mn,Zone order by 3,1,2 Create table #temp_2 (yr numeric, mn numeric, zone varchar(100), cnt numeric)insert into #temp_2SELECT Yr Yr2, Mn Mn2, Zone COL1,SUM(sid) from(select Tm.Yr,Tm.Mn,RM.Zone, count(*) sid from ic_Defects IBA Inner Join ic_LCTMapping RM on IBA.LCT = RM.Center_Description Inner Join (Select distinct m.Mn_Id, m.mn, q.yr from C_Time_Wk w, C_Time_Mn m, C_Time_Qtr q Where q.qtr_id = m.qtr_id and q.yr_id = m.yr_id and q.qtr_id = w.qtr_id and q.yr_id = w.yr_id and w.mn_id = m.mn_id and w.yr_id = m.yr_id) Tm on IBA.Mn_Id = Tm.Mn_Id where Tm.Mn_Id between @mn_id - 11 and @mn_id and RM.Zone = isnull(@Zone, RM.Zone) and RM.LCT = isnull(@LCT, RM.LCT) Group by Tm.Yr,Tm.Mn,RM.Zone )y Group by Yr,Mn,Zone order by 3,1,2 Select a.Yr, a.Mn, a.Zone, cast(((1-(b.Cnt/ a.Cnt))*100) as numeric) from #temp_1 aleft outer join #temp_2 b on a.yr = b.yr and a.mn = b.mn and a.zone = b.zoneENDSET NOCOUNT offendthis query is working fine but we r using temp tables here with out that con't we make this main thing we could need to group yr,mn,Zone there is only on change in two temp tablescon't we?sateesh
sateesh |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-07-22 : 00:35:07
|
| Is there any relationship between the 2 tables?Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
sateesh.sqldba
Starting Member
25 Posts |
Posted - 2010-07-22 : 01:12:47
|
yes i have two columns zone,lctquote: Originally posted by Idera Is there any relationship between the 2 tables?Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH
sateesh |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-07-22 : 01:19:36
|
quote: Originally posted by sateesh.sqldba yes i have two columns zone,lctquote: Originally posted by Idera Is there any relationship between the 2 tables?Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH
sateesh
select count(column from IC)/COUNT(column from IC_DEFECTS),other columns from IC inner join IC_defects D on D.zone=IC.zone ,D.lct=IC.lctgroup by other columns in the select listLimitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
|
|
|