Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR Incorporated.

Katrin and Jim

Month List

dbo.fcn_IsNullOrEmpty

by Jim Sep 13, 2010 11:21 AM

An IsNullOrEmpty function for SQL. I hate that the database I’m working with makes it necessary to write such a thing…

CREATE FUNCTION [dbo].[fcn_IsNullOrEmpty]
(
    @string VARCHAR(4000)
)
RETURNS BIT AS BEGIN DECLARE @isnullorempty BIT SET @isnullorempty = 0

    IF @string IS NULL SET @isnullorempty = 1
    ELSE IF RTRIM(LTRIM(@string)) = '' SET @isnullorempty = 1

    RETURN @isnullorempty
        
END

Tags:

Code