Skip to content

Instantly share code, notes, and snippets.

@Hameds
Last active April 23, 2024 08:23
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Hameds/a97a6242dc8ff5f66980c343693b0a94 to your computer and use it in GitHub Desktop.
Save Hameds/a97a6242dc8ff5f66980c343693b0a94 to your computer and use it in GitHub Desktop.
Replace Arabic ي & ك in SQL Server Database with Persian characters
use [DATABASE_NAME];
DECLARE @Table NVARCHAR(MAX)
DECLARE @Col NVARCHAR(MAX)
DECLARE Table_Cursor CURSOR
FOR
--پيدا کردن تمام فيلدهاي متني تمام جداول ديتابيس جاري
SELECT a.name, --table
b.name --col
FROM sysobjects a,
syscolumns b
WHERE a.id = b.id
AND a.xtype = 'u' --User table
AND (
b.xtype = 99 --ntext
OR b.xtype = 35 -- text
OR b.xtype = 231 --nvarchar
OR b.xtype = 167 --varchar
OR b.xtype = 175 --char
OR b.xtype = 239 --nchar
)
OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @Table,@Col
WHILE (@@FETCH_STATUS = 0)
BEGIN
EXEC (
'update [' + @Table + '] set [' + @Col +
']= REPLACE(REPLACE(CAST([' + @Col +
'] as nvarchar(max)) , NCHAR(1610), NCHAR(1740)),NCHAR(1603),NCHAR(1705)) '
)
FETCH NEXT FROM Table_Cursor INTO @Table,@Col
END CLOSE Table_Cursor DEALLOCATE Table_Cursor
@abilogos
Copy link

abilogos commented Apr 7, 2020

سلام این gist برای mysql هست یا DBMD دیگه ای؟

@Hameds
Copy link
Author

Hameds commented Apr 14, 2020

این مربوط به `SQL Server` است. روی دیتابیس دیگری تست نکردم

@AmirrezaTaleb
Copy link

Thank you very much for your clean coding, but if you complete it for the types and "ی" & "ک" it's so better

@AIAML
Copy link

AIAML commented May 18, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment