|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
evaluate an expression into a variableIn 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 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 > > 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 > |
|||||||||||||||||||||||