Thank you for any help,
Its late and I've not spotted anything obvious except...DON'T prefix with "sp_" you'll incur a needless performance cost. SQL Server will think its a Microsoft Proc and go straight to Master.
CREATE PROCEDURE [dbo].[sp_DataReaderName] @.SID int AS
SELECT
CASE
WHEN A.[CompanyName] IS NULL OR A.[CompanyName] = '' THEN C.[FirstName] +" "+ C.[LastName]
ELSE A.[CompanyName]
END AS DRName,
C.Client_ID
FROM
tblClients C
INNER JOIN
tblClientAddresses A ON C.Client_ID = A.Client_ID
WHERE
(C.Client_ID = @.SID) AND
(A.MailTo=1) AND
(A.EndDate Is Null OR (DatePart(m,A.Enddate) >= DatePart(m,GETDATE()) AND DatePart(d,A.Enddate) >= DatePart(d,GETDATE())))
GO
No comments:
Post a Comment