Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stored procedure call with an ISNULL in the assignment. Invalid Syntax?

Above the call to this stored procedure is another call to a different stored procedure. The first procedure will assign something to @NewIdentifier if it needs to, otherwise I need to use the default SaleId.

exec myStoredProc @SaleId = ISNULL(@NewIdentifier, @SaleId)

It works if I do it this way

declare @Id int
set @Id = ISNULL(@NewIdentifier, @SaleId)
exec myStoredProc @SaleId = @Id

Is it possible to use ISNULL in the assignment of a stored procedure parameter? I'm not sure what is invalid about this syntax.

like image 710
Brandon Avatar asked Sep 30 '10 21:09

Brandon


People also ask

Why Isnull not working in SQL?

Another time ISNULL() will not work is if the data types are not compatible. In SQL Server, the ISNULL() function tries to convert the lower precedence data types into a higher precedence data types. If ISNULL() is not able to convert the data type, it returns an error message.

What is Isnull () operator?

Returns a Boolean value that indicates whether an expression contains no valid data (Null). Syntax. IsNull ( expression ) The required expressionargument is a Variant containing a numeric expression or string expression.

How do I use Isnull in SQL Select statement?

SQL Server ISNULL() FunctionThe ISNULL() function returns a specified value if the expression is NULL. If the expression is NOT NULL, this function returns the expression.

Can we use Isnull in where clause?

We use IS NULL to identify NULL values in a table. For example, if we want to identify records in the employee table with NULL values in the Salary column, we can use IS NULL in where clause.


1 Answers

The parameter must be a constant or a variable. It cannot be an expression.

like image 78
Joe Stefanelli Avatar answered Sep 19 '22 00:09

Joe Stefanelli