Forum Discussion
SQL REPLACE function broken on Fabric Lakehouse SQL Endpoint
- 1 year ago
Hi jpersQ
To remove all carriage return (CHAR(13)) and line feed (CHAR(10)) characters from your SQL Server data, you can utilize the REPLACE function as follows:SELECT [Id],
[Description],
REPLACE(
REPLACE(
REPLACE(Description, CHAR(13) + CHAR(10), ''),
CHAR(13), ''),
CHAR(10), '') AS Cleaned_Description
FROM bronze_Salesforce_event;Best regards,
Ray Minds
http://www.rayminds.com
https://www.linkedin.com/company/rayminds/If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
The query is as above:
SELECT ASCII(SUBSTRING(REPLACE(REPLACE(CAST([Description] AS NVARCHAR(4000)), NCHAR(13), ''), NCHAR(10), ''), 14, 1)) AS D
FROM [dbo].[bronze_Salesforce__event]
where Id= '00UVS000003zCXI2A2'I'm having a hard time getting an anyonymized data example since the issue is finicky.
SELECT ASCII(SUBSTRING(REPLACE(REPLACE(CAST([Description] AS VARCHAR(8000)), CHAR(13), ''), CHAR(10), ''), 14, 1)) AS D
FROM [dbo].[bronze_Salesforce__event]
WHERE Id = '00UVS000003zCXI2A2'
try this once
- jpersQ1 year agoFrequent Visitor
Already tried, it doesn't fix the issue. Neither does casting as NVARCHAR, or casting as NVARCHAR plus using NCHAR(13) and NCHAR(10).
- nilendraFabric1 year agoSuper User
Ok. Try recreate the table using explicit `VARCHAR` column definitions in Spark (e.g., `VARCHAR(40)` instead of generic `STRING`)
- malghani1 year agoNew Member
REPLACE for CRLF or CHAR(10), CHAR(13) is definetly broken. I tested using SSMS and Browser SQL analytics endpoint.
I needed to create the view in order to use the transformed data but failed.I thought of using the a custom scaler function where I was successfully replacing them by looping through characters.
Of course, scaler functions are not allowed end up using CTE. Too much work around in order to fix small thing.