sql server - Better alternative for Stuff and XML path for MS SQT/T-SQL -


i using stuff , xml in query following:

select distinct  payplaninstgroup, dept, name ,stuff((select distinct degreetitle + '<nline>' facttable pid=a.pid , case       when @termid='%' '1' else termid end = case when @termid='%' '1' else a.termid end xml path(''),type).value('(./text())[1]','varchar(max)')     ,1,0,'') degreeterminal ,stuff((select distinct degreeyear + '<nline>' facttable pid=a.pid , case when @termid='%' '1' else termid end = case when @termid='%' '1' else a.termid end xml path(''),type).value('(./text())[1]','varchar(max)')     ,1,0,'') degreeyear  ,stuff((select distinct dbo.aimsdecode(termid,'termid') + ' - ' + classlevel + ' - ' +  classprefix + ' ' + classnumber + ' ' + (isnull(activitydescr,'')) + '<nline>' facttable pid=a.pid , case when @termid='%' '1' else termid end = case when @termid='%' '1' else a.termid end , campusclass @campus , collegeclass @college , colldeptclass @colldept xml path(''),type).value('(./text())[1]','varchar(max)')     ,1,0,'') [classstaught] ,[transcriptonfileinhr] ,[cvonfileindeptorfair] ,stuff((select  distinct guidelines + '<nline>' facttable pid=a.pid , case when @termid='%' '1' else termid end = case when @termid='%' '1' else a.termid end     , campusclass @campus , collegeclass @college , colldeptclass @colldept     xml path(''),type).value('(./text())[1]','varchar(max)')         ,1,0,'') [guidelinesmet] ,isnull(stuff((select  distinct otheracad + '<nline>' facttable pid=a.pid , case when @termid='%' '1' else termid end = case when @termid='%' '1' else a.termid end                       xml path(''),type).value('(./text())[1]','varchar(max)')         ,1,0,''),'') [otheracademiccredentials] ,isnull(stuff((select distinct otherqualifications + '<nline>' facttable pid=a.pid , case when @termid='%' '1' else termid end = case when @termid='%' '1' else a.termid end xml path(''),type).value('(./text())[1]','varchar(max)')     ,1,0,''),'') [otherqualifications] [fairv3].[dbo].facttable  a.termid @termid  , a.campusclass  @campus , a.collegeclass @college , a.colldeptclass @colldept , isnull(flagapprovedexception,'') @flag3 , flagieapproved @flag4 

there multiple stuff in 1 query , causes long query response time. in cases takes on 10 min return 400 rows. give more information how data in table looks , sort of stuff if needs.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -