joe
joe

Reputation: 67

Question regarding SQL arithmetic functions

Can you tell me what am I doing wrong here? Trying to use subtraction here in SQL Server 2005 SELECT statement. There's some type of syntax error here.

isnull(dbo.udf_GetInventory(ga.sku,@date4),0) * costprice - 
isnull(dbo.udf_GetInventory(ga.sku,@date3),0) * costprice  as  date2_diff

Upvotes: 0

Views: 172

Answers (2)

Mikael Eriksson
Mikael Eriksson

Reputation: 139010

There is no syntax-error here if:

  1. You put the statement in a SELECT ... from ga.
  2. ga is a table that has columns sku and costprice of some numeric data type.
  3. You have a scalar-valued function called udf_getinventory that takes two parameters.
  4. The data type of the first parameter to udf_getinventory matches the data type of ga.sku.
  5. The data type of the second parameter matches the data type of @date3.
  6. udf_getinventory returns some numeric data type.
  7. @Date3 is declared before the SELECT statement.
  8. @Date4 is declared before the SELECT statement.

Upvotes: 4

kelloti
kelloti

Reputation: 8951

Not sure about a syntax error, but assuming udf_GetInventory is non-deterministic you're going to get 0 every time...

Upvotes: 0

Related Questions