Thanks for reaching out to Microsoft Q&A.
It looks like you’re encountering an issue where null values in your Cosmos DB documents are being interpreted as 0 in your Synapse Serverless SQL instance. This can happen due to the way SQL handles null values and data types.
In SQL, when you create a view or query data, null values can sometimes be converted to a default value, such as 0, especially if the field is expected to be a numeric type. This behavior can be influenced by the schema definition and the way the data is being cast or interpreted in the SQL query.
To handle this, you can explicitly check for null values in your SQL view and handle them accordingly. For example, you can use the CASE
statement to replace null values with a desired default value or keep them as null.
CREATE VIEW YourView AS
SELECT
id,
customerId,
orderDate,
orderTotal,
CASE
WHEN shippingAddress.state IS NULL THEN 'Unknown'
ELSE shippingAddress.state
END AS State,
shippingAddress.zip
FROM YourContainer;
In this example, if the state
field in the shippingAddress
object is null, it will be replaced with ‘Unknown’. You can adjust this logic to fit your specific needs.
Hope this helps. Do let us know if you any further queries.