SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Sonu619
Posting Yak Master

193 Posts

Posted - 08/08/2012 :  15:22:22  Show Profile  Reply with Quote
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

India
47069 Posts

Posted - 08/08/2012 :  15:25:50  Show Profile  Reply with Quote
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

193 Posts

Posted - 08/08/2012 :  16:02:01  Show Profile  Reply with Quote
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

India
47069 Posts

Posted - 08/08/2012 :  16:12:53  Show Profile  Reply with Quote
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

193 Posts

Posted - 08/08/2012 :  16:26:44  Show Profile  Reply with Quote
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

India
47069 Posts

Posted - 08/08/2012 :  16:32:54  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000