see the code first
CREATE PROC USP_GetLastCSMSavedData
(
@Ticker VARCHAR(10)='',
@ClientCode VARCHAR(10)='',
@LastCSMDate VARCHAR(10)='',
@PageIndex INT = 1,
@PageSize INT = 10
)
AS
BEGIN
DECLARE @SQL VARCHAR(MAX)
DECLARE @ClientName VARCHAR(200)
IF @ClientCode<>''
BEGIN
SELECT @ClientName=ClientName FROM tblClient WHERE ClientCode=@ClientCode
END
ELSE
BEGIN
SET @ClientName=''
END
DECLARE @offset INT
SET @offset = (@PageIndex - 1) * @PageSize
SELECT * FROM (
SELECT CAST(ROW_NUMBER() OVER (ORDER BY LastCSMDeliveredDate DESC) AS INT) AS 'RowNumber',
ID,
Ticker,
c.ClientName,
Earnings,
PrePost,
IIF([QC-ViewAllContent] IS NULL,0,1) HasViewAllContent,
IIF([QCCommentsContent] IS NULL,0,1) HasQCCommentsContent,
InsertedOn,
LastCSMDeliveredDate,
IIF([Action]='I','INSERTED','UPDATED') AS [Action],
UserName
from tblLastCSMDelivered csm
JOIN tblClient c
ON csm.ClientCode=c.ClientCode
WHERE LastCSMDeliveredDate IS NOT NULL
) X
WHERE CAST(X.RowNumber AS INT)> @offset AND CAST(X.RowNumber AS INT)<= (@offset+@PageSize)
AND (@Ticker ='' OR X.Ticker = @Ticker)
AND (@ClientName ='' OR X.ClientName = @ClientName)
AND (@LastCSMDate ='' OR CAST(X.LastCSMDeliveredDate AS DATE)=CAST(@LastCSMDate AS DATE))
ORDER BY X.LastCSMDeliveredDate DESC
END
instead of writing dynamic sql i got a example from a site to apply filter like this way and it is working too but how it is working properly not clear to me.
WHERE
(@Ticker ='' OR X.Ticker = @Ticker)
AND (@ClientName ='' OR X.ClientName = @ClientName)
AND (@LastCSMDate ='' OR CAST(X.LastCSMDeliveredDate AS DATE)=CAST(@LastCSMDate AS DATE))
@Ticker ='' OR X.Ticker = @Ticker again
@ClientName ='' OR X.ClientName = @ClientName
what is the meaning of above kind of filter? how these filters are working. please help me to understand. thanks