0

函数有一些参数,如
@a int, @b int, @c int , @d int

只需要允许,@a、@b、@c、@d 和@a + @b 的组合值都不为空

我试过了,但它也允许其他组合@a + @c

if((@a is not null) or (@b is not null) or (@c is not null) or (@d is not null) or ((@a is not null) and (@b is not null)))

任何人都可以帮助我吗?

4

1 回答 1

0

这个怎么样:

IF
    (
        @a IS NOT NULL 
        AND 
        @c IS NULL
        AND 
        @d IS NULL
    )
    OR
    (
        @b IS NOT NULL
        AND 
        @c IS NULL
        AND 
        @d IS NULL
    )
    OR 
    (
        @c IS NOT NULL
        AND 
        @a IS NULL
        AND 
        @b IS NULL
        AND 
        @d IS NULL
    )
    OR 
    (
        @d IS NOT NULL
        AND 
        @a IS NULL
        AND 
        @b IS NULL
        AND 
        @c IS NULL
    )

或这个:

DECLARE @validate INT;
SELECT @validate = SUM(validate) 
FROM 
    ( 
        SELECT CASE WHEN @a IS NULL THEN 0 ELSE 1 END validate
        UNION
        SELECT CASE WHEN @b IS NULL THEN 0 ELSE 1 END 
        UNION
        SELECT CASE WHEN @c IS NULL THEN 0 ELSE 2 END 
        UNION
        SELECT CASE WHEN @d IS NULL THEN 0 ELSE 2 END 
    ) n;

IF @validate BETWEEN 1 AND 2
于 2013-04-09T17:34:56.310 回答