Hi All,
Need expertise in making how i can make my view run fast. Please find the below Query(view) which i am referring to.
CREATE VIEW [dbo].[finalstatus_view]
AS
WITH ClaimFinalStatus ( CID,CREATEDATE,PlanID,status,[Order] )
AS(
--ran in 4 seconds
SELECT
C.CID,
C.CREATEDATE,
C.planid,
status,
DENSE_RANK() OVER(PARTITION BY CASE WHEN C.CID LIKE '%[ARMS]%'
THEN LTRIM(RTRIM(SUBSTRING(LTRIM(RTRIM(C.CID)),1,PATINDEX('%[^0-9]%',LTRIM(RTRIM(C.CID)))-1))) + LTRIM(RTRIM(C.PLANID))
WHEN C.CID NOT LIKE '%[ARMS]%'
THEN LTRIM(RTRIM(C.CID))+ LTRIM(RTRIM(C.PLANID)) END,c.planid
ORDER BY C.CREATEDATE DESC) AS 'Order'
FROM dbo.ABC c
where c.cid='%1419282888%'
)
SELECT CID,status,PlanID
FROM ClaimFinalStatus
WHERE [Order] = 1
Basically I am getting finalstatus of a CID , The above Query for one CID is running pretty fast in 3-6 seconds but this is view which we will join with other tables so i ran like the below it is running ~10 minutes. Can any one suggest how Can i tweak my Query in the view to run fast enough. Also ABC table is having 3.7 Million CID's and I have a Primary Key and clustered index on CID. I have changed the original table name and field names . Thanks any help can be appreciated .
select * from [dbo].[finalstatus_view]
where cid like '%141928888%'
Thanks,
Kalyan