Select column, if blank select from another

前端 未结 4 1416
谎友^
谎友^ 2020-12-24 11:29

How does one detect whether a field is blank (not null) and then select another field if it is?

What I really need is a IsBlank function that works the same as IsNul

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 11:59

    You could always write an isBlank() function, something like

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE FUNCTION isBlank
    (
        @CheckExpression varchar, @ReplacementExpression varchar
    )
    RETURNS varchar
    AS
    BEGIN
        IF @CheckExpression IS NOT NULL
        BEGIN
            IF @CheckExpression='' or LEN(@CheckExpression) = 0
            RETURN @ReplacementExpression
        ELSE
            RETURN @CheckExpression
        END
    
        RETURN @ReplacementExpression
    END
    GO
    

提交回复
热议问题