USE [PET]
GO
/****** Object: UserDefinedFunction [dbo].[Ye] Script Date: 7/19/2017 10:47:55 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*
-- =============================================
-- Author: kiani
-- Create date: 921106
-- Description: تبدیل ی برای سرچ ها
SELECT ASCII('ی'),ASCII('ي'), UNICODE('ی'),UNICODE('ي')
select nchar(1609),nchar(1610),nchar(1740),nchar(1603),nchar(1705),NCHAR(247), NCHAR(1662)
-- =============================================
*/
ALTER FUNCTION [dbo].[Ye] (@MyStringIn VARCHAR(255))
RETURNS NVarchar(255)
AS
BEGIN
DECLARE @MyStringOut as NVARCHAR(255)
--SET @MyStringOut=REPLACE(REPLACE(@MyStringIn, NCHAR(1610), NCHAR(1740)), NCHAR(1603), NCHAR(1705))
SET @MyStringOut=REPLACE(REPLACE(REPLACE(REPLACE(@MyStringIn, NCHAR(1610), NCHAR(1740)), NCHAR(1603), NCHAR(1705)), NCHAR(1609), NCHAR(1740)), NCHAR(247), NCHAR(1662))
Return @MyStringOut
/*
Use [MDB1
DECLARE @Table NVARCHAR(MAX),@Column NVARCHAR(MAX)
DECLARE Table_Cursor CURSOR
FOR
--پیدا کردن تمام فیلدهای متنی تمام جداول دیتابیس جاری
SELECT T.name, /* Table */
C.name /* Column */
FROM sysobjects T,syscolumns C
WHERE T.id = C.id AND T.xtype = 'u' /* User Table */
AND (C.xtype = 99 /* ntext */
OR C.xtype = 35 /* text */
OR C.xtype = 231 /* nvarchar */
OR C.xtype = 167 /* varchar */
OR C.xtype = 175 /* char */
OR C.xtype = 239 /* nchar */)
OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @Table,@Column
WHILE (@@FETCH_STATUS = 0)
BEGIN
EXEC ('Update [' + @Table + '] Set [' + @Column + '] = REPLACE(REPLACE(CAST([' + @Column + '] as nvarchar(max)), NCHAR(1610), NCHAR(1740)), NCHAR(1603), NCHAR(1705))')
--EXEC ('Update [' + @Table + '] Set [' + @Column + '] = REPLACE(REPLACE(CAST([' + @Column + '] as nvarchar(max)), NCHAR(1610), NCHAR(1740)), NCHAR(1705), NCHAR(1603))')
FETCH NEXT FROM Table_Cursor INTO @Table,@Column
END CLOSE Table_Cursor
DEALLOCATE Table_Cursor
*/
END