磨剪子磨菜刀君 2010-04-25
代码如下:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: xoyozo -- Create date: 2010-4-17 -- Description: 提供中文首字母 -- ============================================= CREATE FUNCTION fun_getPY ( @str NVARCHAR(4000) ) RETURNS NVARCHAR(4000) AS BEGIN DECLARE @word NCHAR(1),@PY NVARCHAR(4000) SET @PY='' WHILE len(@str)>0 BEGIN SET @word=left(@str,1) SET @PY=@PY+(CASE WHEN unicode(@word) BETWEEN 19968 AND 19968+20901 THEN (SELECT TOP 1 PY FROM ( SELECT 'A' AS PY,N'' AS word UNION ALL SELECT 'B',N'簿' UNION ALL SELECT 'C',N'e' UNION ALL SELECT 'D',N'z' UNION ALL SELECT 'E',N'' UNION ALL SELECT 'F',N'v' UNION ALL SELECT 'G',N'B' UNION ALL SELECT 'H',N'' UNION ALL SELECT 'J',N'h' UNION ALL SELECT 'K',N'i' UNION ALL SELECT 'L',N'w' UNION ALL SELECT 'M',N'' UNION ALL SELECT 'N',N'' UNION ALL SELECT 'O',N'a' UNION ALL SELECT 'P',N'曝' UNION ALL SELECT 'Q',N'' UNION ALL SELECT 'R',N'U' UNION ALL SELECT 'S',N'R' UNION ALL SELECT 'T',N'X' UNION ALL SELECT 'W',N'F' UNION ALL SELECT 'X',N'R' UNION ALL SELECT 'Y',N'' UNION ALL SELECT 'Z',N'' ) T WHERE word>=@word COLLATE Chinese_PRC_CS_AS_KS_WS ORDER BY PY ASC) ELSE @word END) SET @str=right(@str,len(@str)-1) END RETURN @PY END
代码如下:
select * from 表 where fun_getPY(字段) like N'%zgr%'
代码如下:
DataClasses1DataContext db = new DataClasses1DataContext(); var q = from d in db.Documents where d.Title.Contains("zgr") || db.fun_getPY(d.Title).Contains("zgr") select d;