Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query Help

Author  Topic 

Sonu619
Posting Yak Master

202 Posts

Posted - 2012-08-08 : 15:22:22
Hi Guys,

Any advise whould be great, There is any way i can improve below part of my S.p?


select distinct
pm.MId,
e.DService,
ps.pId,
0 NCount,

(select
(Select COUNT(distinct o.OId)
from tOrder o
inner join tL L on O.OId = L.OId
and (OrderChoiceId like '%228%'
)
and PrId = 2
where o.OrderTypeId in(4)
and o.EncounterId = e.EncounterId
and O.IsDeleted=0)

+

( Select COUNT(distinct o.OrderId)
from tOrder o
join tOrderC oc on o.OId = oc.OId
and oc.PId = 2
and OC.IsDeleted=0
where o.OTId in(2,5)
and o.EId = e.EId
and O.IsDeleted=0)

+

( Select COUNT(distinct o.OrderId)
from tblEHROrder O
INNER JOIN tOrderI OI on O.OId = OI.OId
and oi.PId = 2
and OI.IsDeleted = 0
where o.OTId in(2,5)
and o.EId = e.EId
and O.IsDeleted=0)
) OrSCount,
dbo.udf_GetPrimaryPayer(e.EId) Payor,
e.PUId ProvidId,


from #temp1 e
left outer join TSign VS ON E.EId = VS.EId
and VS.IsVoided = 0
INNER JOIN tSub PS ON PS.PId = E.PUId
INNER JOIN tPM PM ON PM.MId = PS.MId
LEFT OUTER JOIN Prov p ON P.PUId = E.PUId

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-08 : 15:25:50
without understanding what it does its hard to suggest an alternative. post some sample data and explain what you're trying to get out of them. then we might be able to suggest a better approach

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sonu619
Posting Yak Master

202 Posts

Posted - 2012-08-08 : 16:02:01
In this section i am calculating and populating a field "OStatusCount". Could you please tell me how i can find out which query is running very slow in S.P, Which syntax should i use before i after query?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-08 : 16:12:53
quote:
Originally posted by Sonu619

In this section i am calculating and populating a field "OStatusCount". Could you please tell me how i can find out which query is running very slow in S.P, Which syntax should i use before i after query?



have a look at execution plan. run the query with display actual execution plan option enabled in SSMS and you'll be able to view it.

Analyse plans and start with costly steps based on % values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Sonu619
Posting Yak Master

202 Posts

Posted - 2012-08-08 : 16:26:44
I am using

SET STATISTICS IO ON
SET STATISTICS TIME ON
SET STATISTICS PROFILE ON

in my store prcedure. My question what actually i am looking here. I have never done this one before. Thanks for help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-08 : 16:32:54
see

http://axcs.blogspot.com/2005/11/sql-server-query-execution-plan.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -