I am copying data from an Azure SQL database into Azure Synapse using the Copy Data activity. I am attempting to use Polybase as the copy method. This works successfully on most tables but I have a source and destination table with the following columns:
Fee DECIMAL(18,2) NULL,
FeeReason VARCHAR(500) NOT NULL
For reasons beyond my control, I am unable to change the columns to allow NULLs in the FeeReason column. In the table, if Fee is NULL, then FeeReason is an empty string.
When I try and copy the table from Azure SQL DB into Synapse I get an error for the Fee column when that value is NULL:
ErrorCode=FailedDbOperation, ......HadoopSqlException: Error converting data type VARCHAR to DECIMAL.....Detailed Message=Empty string can't be converted to DECIMAL.....
and the solution to this problem is to set the "Use Type Default" setting to false as per loading-to-decimal-column
However, making this change results in the FeeReason value to be NULL in Synapse when the value is an empty string in the source (Azure DB). Is there anyway I can set "Use Type Default" set to False for decimal columns only?
I have a terribly dirty solution to this which involves creating a BIT column in the source database called FeeReasonIsEmpty and flag records where the FeeReason is actually an empty string and once the data has been copied over, I can just update the NULL values to empty strings where relevant. I want to avoid this if possibly because in reality I have multiple tables with multiple decimal columns and multiple varchar/nvarchar columns with empty strings that need to be retained. This dirty solution would mean I'd need to create an "IsEmpty" column for each of those and I don't really want to do that. Thank-you.