question

jazpar avatar image
jazpar asked

Remove carriage return in chinese character

Hi I need to remove carriage return in a column. But one company have a lot of chinese character, and my function return ??? instead. Function: create FUNCTION [dbo].[fnc_RemoveCharacters_New](@Text nvarchar(max)) RETURNS nvarchar(4000) AS BEGIN -- Declare the return variable here DECLARE @ReturnText nvarchar(4000) DECLARE @cnvText nvarchar(4000) SET @cnvText = cast(@Text as nvarchar(4000)) SET @ReturnText = convert(nvarchar(4000),REPLACE(@cnvText, ';',':')) SET @ReturnText = convert(nvarchar(4000),REPLACE(@ReturnText, char(13),'')) /*Carriage return */ SET @ReturnText = convert(nvarchar(4000),REPLACE(@ReturnText, CHAR(9),'')) /*Horozontal tab replaced with 3 spaces*/ SET @ReturnText = convert(nvarchar(4000),REPLACE(@ReturnText, CHAR(10),'')) /*Line feed*/ RETURN @ReturnText end go Test: declare @test2 nvarchar(100) declare @test nvarchar(100) set @test = '锥重 型)1G2686' set @test2 ='锥孔平滑轴承钻夹头(重型)1G2686' select dbo.fnc_RemoveCharacters_New(@Test) AS test, dbo.fnc_RemoveCharacters_New(@Test2) as Test2 Result: Test = ?? ?)1G2686 Test2 = ?????????(??)1G2686 So function removes carriage return but also dos not recognize the chinese characters ?? Hope someone have an idea :-) BR Jan Update: By mistake I had written @Text varchar(max) it was @Text nvarchar(max) And the result is equal Result: Test = ???)1G2686 Test2 = ?????????(??)1G2686
sqlsql server 2012
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·
Where do you see the `???` being returned? Is it because the font you're using doesn't support the character set required to display the data?
0 Likes 0 ·
jazpar avatar image jazpar commented ·
Hi I see these data return in the select statement. In the table I have all the chinese characters, but when retrewing in my view using the function the result is ???. The function is used because of som issue when using the data in excel and carriage return is present. BR Jan
0 Likes 0 ·
jiken avatar image
jiken answered
Hi jazpar, Please change passing parameter datatype from varchar to nvarchar. Please check below code. Your function ALTER FUNCTION [dbo].[fnc_RemoveCharacters_New] ( @Text **varchar**(max) ) RETURNS nvarchar(4000) Updated function ALTER FUNCTION [dbo].[fnc_RemoveCharacters_New] ( @Text **Nvarchar**(max) ) RETURNS nvarchar(4000) Your set statement set @test = '锥重 型)1G2686' set @test2 = '锥孔平滑轴承钻夹头(重型)1G2686' Updated set statement set @test = **N**'锥重 型)1G2686' set @test2 = **N**'锥孔平滑轴承钻夹头(重型)1G2686' Happy coding! Enjoy!
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jazpar avatar image
jazpar answered
Hi I can see that placing this N helps :-) But how can I do this in my dataload from one table too antoher (SSIS package). The below is a part of the select statement: SELECT p.PURCHID, s.INVENTTRANSID, p.LINENUMBER, p.itemid, p.PROCUREMENTCATEGORY, d.ID AS DATAAREAID, s.CompanyRecId, p.PURCHUNIT, convert(nvarchar(100),dbo.FIT_RemoveCharacters(p.NAME)) AS NAME FROM stLedgerVendPurchInvoiceTrans s INNER JOIN dCompany d ON s.CompanyRecId = d.DataAreaId LEFT OUTER JOIN dbo.dPurchLine p ON s.INVENTTRANSID = p.INVENTTRANSID AND s.CompanyRecId = p.CompanyRecId GROUP BY p.PURCHID, s.INVENTTRANSID, p.LINENUMBER, p.itemid, p.PROCUREMENTCATEGORY, d.ID, s.CompanyRecId, p.PURCHUNIT , p.CURRENCYCODE, p.name, p.[CURRENCY UNIT PRICE], p.EXCHRATE, p.[UNIT PRICE], p.ASSETID, p.INVENTSITEID, p.INVENTLOCATIONID, s.LedgerDimension , s.[OVERALL ID], s.InvoiceDateId Can this be done in the function ? Or can the function be called with this ? BR Jan
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.