Last active
March 30, 2023 11:59
-
-
Save zonaro/a9674486dcc89c4d2fea4ec6d6091eab to your computer and use it in GitHub Desktop.
IfBlank function for SQL Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ============================================= | |
-- Author: Zonaro | |
-- Create date: 30/03/2023 | |
-- Description: Return a replacement value if expression is null or contains only whitespace | |
-- ============================================= | |
CREATE FUNCTION IfBlank | |
( | |
@expression varchar(max), | |
@replacement varchar(max) | |
) | |
RETURNS varchar(max) | |
AS | |
BEGIN | |
RETURN isnull(nullif(ltrim(rtrim(@expression)),''),@replacement) | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment