Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here i have one query that i have written.problem is that it takes hell lot of time to execute fully.So i want to remove subquery from this query for that what i have to do.?please explain me.

What I have tried:

SQL
select 
--d1.C_FS_Code
--,fs.C_Name
--ar.C_Name area,us.C_Name Designation
dc.c_description grade,ds1.C_DSC_Code,ca.C_Name speciality,sub.C_Name subarea
,DateName( month , DateAdd( month , MONTH(d1.d_date_report) , 0 ) - 1 ) mn,STUFF((
select ',',day(d.D_Date_Report) from Tbl_dwr d
join tbl_dwr_details ds on ds.N_Srno=d.N_Srno
where MONTH(d.D_Date_Report)>=4
and YEAR(d.D_Date_Report)=2015 
and MONTH(d.d_date_report)=MONTH(d1.d_date_report)
and year(d.d_date_report)=year(d1.d_date_report) 
--and day(d.D_Date_Report)=day(d1.D_Date_Report)
and  ds1.C_DSC_Code=ds.C_DSC_Code
group by MONTH(d.D_Date_Report) ,YEAR(d.D_Date_Report),d.d_date_report,ds.C_DSC_Code for xml path('') ),1,1,'') dates
from Tbl_dwr d1
join tbl_dwr_details ds1 on ds1.N_Srno=d1.N_Srno
--join tbl_fs_mst fs on fs.C_Code=d1.C_FS_Code
--join Tbl_User_Access us on us.N_Type=fs.N_Type
--join Tbl_Area_Mst ar on ar.C_Code=fs.C_Area_Code
join tbl_doc_grade_mst dc on dc.c_code=ds1.c_doc_grade
join Tbl_Doc_Stock_Chem_Add_Mst sd on sd.C_Code=ds1.C_DSC_Code
join Tbl_Category_Mst ca on ca.C_Code=sd.C_Category
join Tbl_Sub_Area_Mst sub on sub.C_Code=sd.C_Subarea_Code
where MONTH(d1.D_Date_Report)>=4
and YEAR(d1.D_Date_Report)=2015 
--and ds1.C_DSC_Code='D051767'
group by MONTH(d1.D_Date_Report),YEAR(d1.D_Date_Report),ds1.C_DSC_Code
--,d1.D_Date_Report,
--,d1.C_FS_Code,fs.C_Name
--,ar.C_Name,us.C_Name 
,dc.c_description ,ds1.C_DSC_Code,ca.C_Name,sub.C_Name


this is my query..
Posted
Updated 23-Feb-16 4:43am
v2

1 solution

You can use table variable Table Variables In T-SQL[^]

or Common table expression Using Common Table Expressions[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900