I have the following stored procedure...
And it calls this function...
Could I eliminate this function...
Our SQL Tuning Advisory errors out when analyzing the trace on this application.
Also, the Quicksilver table has just less than a million rows...
Any help or advice would be great.
Code:
CREATE PROCEDURE [dbo].[Quicksilver_Get_Charges_Pmts_Adj_Amt]
(
@sSiteType varchar(5)
,@sState varchar(5)
,@sStartMonth varchar(6)
,@sEndMonth varchar(6)
,@sLOB varchar(50)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT
T1.PRType
, isnull(SUM(CASE WHEN (T1.IT='B') THEN T1.Total_Amt ELSE 0 END),0) "B"
, isnull(SUM(CASE WHEN (T1.IT='D') THEN T1.Total_Amt ELSE 0 END),0) "D"
, isnull(SUM(CASE WHEN (T1.IT='E') THEN T1.Total_Amt ELSE 0 END),0) "E"
, isnull(SUM(CASE WHEN (T1.IT='H') THEN T1.Total_Amt ELSE 0 END),0) "H"
, isnull(SUM(CASE WHEN (T1.IT='O') THEN T1.Total_Amt ELSE 0 END),0) "O"
, isnull(SUM(CASE WHEN (T1.IT='R') THEN T1.Total_Amt ELSE 0 END),0) "R"
, isnull(SUM(CASE WHEN (T1.IT='S') THEN T1.Total_Amt ELSE 0 END),0) "S"
, isnull(SUM(T1.Total_Amt),0) "Total"
FROM
(
SELECT
Q.Site
, isnull(M.NewIT,Q.IT) "IT"
, Q.LockBox
, Q.YearMonth
, Q.PRType
, Q.PRCode
, Q.Total_Count
, Q.Total_Amt
FROM
Quicksilver AS Q
JOIN fn_QuickSilver_SiteList(@sSiteType,@sState) SL ON (Q.Site=SL.sSiteID)
LEFT JOIN Quicksilver_PRCode_IT_Map M ON (Q.PRType=M.PRType) AND (Q.PRCode=M.PRCode)
JOIN fn_ParseDelimitedStrings(@sLOB,',') L ON (Q.Location_Code=convert(int, L.Value))
WHERE
(Q.YearMonth BETWEEN @sStartMonth AND @sEndMonth)
AND (Q.PRType IN ('C', 'P', 'A'))
)T1
WHERE
(T1.IT IN ('B','D','E','H','O','R','S'))
GROUP BY
T1.PRType
And it calls this function...
Code:
ALTER FUNCTION [dbo].[fn_QuickSilver_SiteList]
(
@SiteType varchar(3)
, @SiteState varchar(2)
)
RETURNS @t TABLE (sSiteID varchar(10))
BEGIN
IF @SiteType = 'COM'
BEGIN
INSERT @t (sSiteID)
SELECT DISTINCT CPCODE
FROM MEDGROUP G
JOIN MEDLOCATIONS L ON G.CPCODE = L.LOCCPCODE
WHERE (REPLACE(CPSHORTNAME, ' ', '') NOT LIKE '%-OPM%')
AND ((@SiteState = '') OR (L.LOCSTATE=@SiteState))
END
IF @SiteType = 'OPM'
BEGIN
INSERT @t (sSiteID)
SELECT DISTINCT CPCODE
FROM MEDGROUP G
JOIN MEDLOCATIONS L ON G.CPCODE = L.LOCCPCODE
WHERE (REPLACE(CPSHORTNAME, ' ', '') LIKE '%-OPM%')
AND ((@SiteState = '') OR (L.LOCSTATE=@SiteState))
END
IF @SiteType = 'ALL'
BEGIN
INSERT @t (sSiteID)
SELECT DISTINCT LOCCPCODE
FROM MEDLOCATIONS L
WHERE ((@SiteState = '') OR (L.LOCSTATE=@SiteState))
END
RETURN
END
Could I eliminate this function...
Our SQL Tuning Advisory errors out when analyzing the trace on this application.
Also, the Quicksilver table has just less than a million rows...
Any help or advice would be great.