Here is the current SP
SELECT dbo.PolicyHolderDataT.*, MuellerFormT.*, MuellerGlobalData.dbo.JoinedCustomerTable.*, dbo.StateT.*, dbo.UnderwriterAgents.* FROM MuellerGlobalData.dbo.InternetAuthorizedCompanies
INNER JOIN MuellerGlobalData.dbo.JoinedCustomerTable ON MuellerGlobalData.dbo.InternetAuthorizedCompanies.nJoinedCustomerTable_id = MuellerGlobalData.dbo.JoinedCustomerTable.ID
INNER JOIN dbo.CustomerT ON MuellerGlobalData.dbo.JoinedCustomerTable.CustomerNumber = dbo.CustomerT.CustomerNumber INNER JOIN dbo.PolicyHolderDataT INNER JOIN dbo.StateT ON dbo.PolicyHolderDataT.SurveyStateID = dbo.StateT.StateID ON dbo.CustomerT.ID = dbo.PolicyHolderDataT.CustomerID
LEFT OUTER JOIN dbo.MuellerFormT ON dbo.PolicyHolderDataT.ControlIDNumber = dbo.MuellerFormT.InsuredID LEFT OUTER JOIN dbo.UnderwriterAgents ON dbo.PolicyHolderDataT.AgencyCode = dbo.UnderwriterAgents.cAgentCode
WHERE ( 1=1 AND MuellerGlobalData.dbo.InternetAuthorizedCompanies.nInternetUsers_id = @nInternetUsers_id)
and CustomerT.CustomerNumber = ISNULL(@nCustomerID,CustomerT.CustomerNumber)
and PolicyHolderDataT.PolicyNumber LIKE ISNULL(@cPolicyNumberVar,PolicyHolderDataT.PolicyNumber)
and ControlIDNumber = ISNULL(@nControlIDNumber,ControlIDNumber)
and StatusIDLookup = ISNULL(@cStatusIDLookup,StatusIDLookup)
and AgencyCode = ISNULL(@cAgencyCode,AgencyCode)
and (UnderwriterAgents.cUnderwriterCode =ISNULL(@cUnderwriterCode,UnderwriterAgents.cUnderwriterCode) OR UnderwriterAgents.cUnderwriterTechCode = ISNULL(@cUnderwriterCode,UnderwriterAgents.cUnderwriterTechCode)
and PolicyHolderDataT.DateCompleted BETWEEN ISNULL(@dCompletedFrom,PolicyHolderDataT.DateCompleted) and ISNULL(@dCompletedTo,PolicyHolderDataT.DateCompleted)
and PolicyHolderDataT.DateReceived BETWEEN ISNULL(@dReceivedFrom,PolicyHolderDataT.DateReceived) and ISNULL(@dReceivedTo,PolicyHolderDataT.DateReceived)
and PolicyHolderDataT.EffectiveDate BETWEEN ISNULL(@dEffectiveFrom,PolicyHolderDataT.EffectiveDate) and ISNULL(@dEffectiveTo,PolicyHolderDataT.EffectiveDate)
and PolicyHolderDataT.PolicyHolderName2 LIKE ISNULL(@cPolicyHolderName2Var,PolicyHolderDataT.PolicyHolderName2)
ORDER BY ISNULL(@cSortBy,PolicyHolderDataT.ControlIDNumber) DESC
Its blowing up on the order by clause , does anyone know of a good way to pass in the order by clause and have it recognized and work ? I am trying to avoid string concatination with an EXEC statement due to compiling concerns.
Thanks,
Pat