Skip to content

Instantly share code, notes, and snippets.

@hendrasyp
Created December 23, 2022 10:51
Show Gist options
  • Save hendrasyp/54614ff2bac2331548c0f2ebb56c9334 to your computer and use it in GitHub Desktop.
Save hendrasyp/54614ff2bac2331548c0f2ebb56c9334 to your computer and use it in GitHub Desktop.
SQL Server - Stored Procedure Show Data
CREATE PROCEDURE [Schema].[SP_Name] (@Param [DataType(Size)] = DEFAULT_VALUE)
AS
BEGIN
-- Condition With Coalesce
WHERE COALESCE(id, NULL) = COALESCE(@paramId, id, NULL) -- EQUALS
AND COALESCE(name, '%') LIKE COALESCE('%' + @paramName + '%', name, '%') -- LIKE
AND ( -- DATE RANGE
CONVERT(VARCHAR(10) , date, 111) >= CONVERT(VARCHAR(10) , @FromDate, 111) AND
CONVERT(VARCHAR(10) , date, 111) <= CONVERT(VARCHAR(10) , @ToDate, 111)
);
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment