Returning decimal values from Advanced Queries

Returning decimal values from Advanced Queries

  
When you are trying to return decimal values from advanced queries you might get this runtime error:
"Decimal byte array constructor requires an array of length * containing valid decimal bytes."
This means that you are trying to assign a decimal value to an attribute with different length or decimal places.

When this happens you should use the T-SQL function CONVERT()

For instance if you have an Advanced Query with the following SQL:
SELECT 9/2
and the output structure has a single attribute with Length=37 and Decimals=8 you should change the SQL to:
SELECT CONVERT (decimal(37,8), 9 /2)


For more information refer to Microsoft SQL Server Books Online\Transact-SQL Reference\CAST and CONVERT