Home All Groups Group Topic Archive Search About

evaluate an expression into a variable

Author
1 Sep 2005 7:17 PM
Jon LaRosa
Hi all,

In a stored procedure I am trying to do this:
SET @Barr = (@Foo is NULL)

so I don't have to use this inelegant and less efficient code:
IF @Foo is NULL
    SET @Barr = 1
ELSE
    SET @Barr = 0


anyone know if this is possible?  I am getting the error:
Error 156: Incorrect syntax near the keyword 'is'

thanks in advance.

Jon LaRosa
jlarosa at alumni daht brown daht edu

Author
1 Sep 2005 7:37 PM
Alejandro Mesa
You can use a "case" expression.

set @Barr = case when @Foo is NULL then 1 else 0 end


AMB

Show quote
"Jon LaRosa" wrote:

> Hi all,
>
> In a stored procedure I am trying to do this:
> SET @Barr = (@Foo is NULL)
>
> so I don't have to use this inelegant and less efficient code:
> IF @Foo is NULL
>     SET @Barr = 1
> ELSE
>     SET @Barr = 0
>
>
> anyone know if this is possible?  I am getting the error:
> Error 156: Incorrect syntax near the keyword 'is'
>
> thanks in advance.
>
> Jon LaRosa
> jlarosa at alumni daht brown daht edu
>
>
Author
1 Sep 2005 7:53 PM
Trey Walpole
SELECT @Barr = CASE WHEN @Foo IS NULL THEN 1 ELSE 0 END

Jon LaRosa wrote:
Show quote
> Hi all,
>
> In a stored procedure I am trying to do this:
> SET @Barr = (@Foo is NULL)
>
> so I don't have to use this inelegant and less efficient code:
> IF @Foo is NULL
>     SET @Barr = 1
> ELSE
>     SET @Barr = 0
>
>
> anyone know if this is possible?  I am getting the error:
> Error 156: Incorrect syntax near the keyword 'is'
>
> thanks in advance.
>
> Jon LaRosa
> jlarosa at alumni daht brown daht edu
>

AddThis Social Bookmark Button