博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  1 --获取全拼
  2 DECLARE @str VARCHAR(max)
  3 SET @str= [dbo].[fn_Getquanpin]('中山')
  4 PRINT(@str)
  5 create function [dbo].[fn_Getquanpin](@str varchar(100))
  6 returns varchar(8000)
  7 as
  8 begin
  9  declare @re varchar(8000),@crs varchar(10)
 10  declare @strlen int 
 11  select @strlen=len(@str),@re=''
 12  while @strlen>0
 13  begin  
 14   set @crs= substring(@str,@strlen,1)
 15       select @re=
 16         case
 17         when @crs<'' then @crs
 18         when @crs<='' then 'a'
 19         when @crs<='' then 'ai'
 20         when @crs<='' then 'an'
 21         when @crs<='' then 'ang'
 22         when @crs<='' then 'ao'
 23         when @crs<='' then 'ba'
 24         when @crs<='' then 'bai'
 25         when @crs<='' then 'ban'
 26         when @crs<='' then 'bang'
 27         when @crs<='' then 'bao'
 28         when @crs<='' then 'bei'
 29         when @crs<='' then 'ben'
 30         when @crs<='' then 'beng'
 31         when @crs<='' then 'bi'
 32         when @crs<='' then 'bian'
 33         when @crs<='' then 'biao'
 34         when @crs<='' then 'bie'
 35         when @crs<='' then 'bin'
 36         when @crs<='' then 'bing'
 37         when @crs<='' then 'bo'
 38         when @crs<='簿' then 'bu'
 39         when @crs<='' then 'ca'
 40         when @crs<='' then 'cai'
 41         when @crs<='' then 'can'
 42         when @crs<='' then 'cang'
 43         when @crs<='' then 'cao'
 44         when @crs<='' then 'ce'
 45         when @crs<='' then 'cen'
 46         when @crs<='' then 'ceng'
 47         when @crs<='' then 'cha'
 48         when @crs<='' then 'chai'
 49         when @crs<='' then 'chan'
 50         when @crs<='' then 'chang'
 51         when @crs<='' then 'chao'
 52         when @crs<='' then 'che'
 53         when @crs<='' then 'chen'
 54         when @crs<='' then 'cheng'
 55         when @crs<='' then 'chi'
 56         when @crs<='' then 'chong'
 57         when @crs<='' then 'chou'
 58         when @crs<='' then 'chu'
 59         when @crs<='' then 'chuai'
 60         when @crs<='' then 'chuan'
 61         when @crs<='' then 'chuang'
 62         when @crs<='' then 'chui'
 63         when @crs<='' then 'chun'
 64         when @crs<='' then 'chuo'
 65         when @crs<='' then 'ci'
 66         when @crs<='' then 'cong'
 67         when @crs<='' then 'cou'
 68         when @crs<='' then 'cu'
 69         when @crs<='' then 'cuan'
 70         when @crs<='' then 'cui'
 71         when @crs<='籿' then 'cun'
 72         when @crs<='' then 'cuo'
 73         when @crs<='' then 'da'
 74         when @crs<='' then 'dai'
 75         when @crs<='' then 'dan'
 76         when @crs<='' then 'dang'
 77         when @crs<='' then 'dao'
 78         when @crs<='' then 'de'
 79         when @crs<='' then 'den'
 80         when @crs<='' then 'deng'
 81         when @crs<='' then 'di'
 82         when @crs<='' then 'dia'
 83         when @crs<='' then 'dian'
 84         when @crs<='' then 'diao'
 85         when @crs<='' then 'die'
 86         when @crs<='' then 'ding'
 87         when @crs<='' then 'diu'
 88         when @crs<='' then 'dong'
 89         when @crs<='' then 'dou'
 90         when @crs<='' then 'du'
 91         when @crs<='' then 'duan'
 92         when @crs<='' then 'dui'
 93         when @crs<='' then 'dun'
 94         when @crs<='' then 'duo'
 95         when @crs<='' then 'e'
 96         when @crs<='' then 'en'
 97         when @crs<='' then 'eng'
 98         when @crs<='' then 'er'
 99         when @crs<='' then 'fa'
100         when @crs<='' then 'fan'
101         when @crs<='' then 'fang'
102         when @crs<='' then 'fei'
103         when @crs<='' then 'fen'
104         when @crs<='' then 'feng'
105         when @crs<='' then 'fo'
106         when @crs<='' then 'fou'
107         when @crs<='' then 'fu'
108         when @crs<='' then 'ga'
109         when @crs<='' then 'gai'
110         when @crs<='' then 'gan'
111         when @crs<='' then 'gang'
112         when @crs<='' then 'gao'
113         when @crs<='' then 'ge'
114         when @crs<='' then 'gei'
115         when @crs<='' then 'gen'
116         when @crs<='' then 'geng'
117         when @crs<='' then 'gong'
118         when @crs<='' then 'gou'
119         when @crs<='' then 'gu'
120         when @crs<='詿' then 'gua'
121         when @crs<='' then 'guai'
122         when @crs<='' then 'guan'
123         when @crs<='' then 'guang'
124         when @crs<='' then 'gui'
125         when @crs<='' then 'gun'
126         when @crs<='' then 'guo'
127         when @crs<='' then 'ha'
128         when @crs<='' then 'hai'
129         when @crs<='' then 'han'
130         when @crs<='' then 'hang'
131         when @crs<='' then 'hao'
132         when @crs<='' then 'he'
133         when @crs<='' then 'hei'
134         when @crs<='' then 'hen'
135         when @crs<='' then 'heng'
136         when @crs<='' then 'hong'
137         when @crs<='' then 'hou'
138         when @crs<='' then 'hu'
139         when @crs<='' then 'hua'
140         when @crs<='' then 'huai'
141         when @crs<='' then 'huan'
142         when @crs<='' then 'huang'
143         when @crs<='' then 'hui'
144         when @crs<='' then 'hun'
145         when @crs<='' then 'huo'
146         when @crs<='' then 'ji'
147         when @crs<='' then 'jia'
148         when @crs<='' then 'jian'
149         when @crs<='' then 'jiang'
150         when @crs<='' then 'jiao'
151         when @crs<='' then 'jie'
152         when @crs<='' then 'jin'
153         when @crs<='' then 'jing'
154         when @crs<='' then 'jiong'
155         when @crs<='' then 'jiu'
156         when @crs<='' then 'ju'
157         when @crs<='' then 'juan'
158         when @crs<='' then 'jue'
159         when @crs<='' then 'jun'
160         when @crs<='' then 'ka'
161         when @crs<='' then 'kai'
162         when @crs<='' then 'kan'
163         when @crs<='' then 'kang'
164         when @crs<='' then 'kao'
165         when @crs<='' then 'ke'
166         when @crs<='' then 'ken'
167         when @crs<='' then 'keng'
168         when @crs<='' then 'kong'
169         when @crs<='' then 'kou'
170         when @crs<='' then 'ku'
171         when @crs<='' then 'kua'
172         when @crs<='' then 'kuai'
173         when @crs<='' then 'kuan'
174         when @crs<='' then 'kuang'
175         when @crs<='' then 'kui'
176         when @crs<='' then 'kun'
177         when @crs<='' then 'kuo'
178         when @crs<='' then 'la'
179         when @crs<='' then 'lai'
180         when @crs<='' then 'lan'
181         when @crs<='' then 'lang'
182         when @crs<='' then 'lao'
183         when @crs<='' then 'le'
184         when @crs<='' then 'lei'
185         when @crs<='' then 'leng'
186         when @crs<='' then 'li'
187         when @crs<='' then 'lia'
188         when @crs<='' then 'lian'
189         when @crs<='' then 'liang'
190         when @crs<='' then 'liao'
191         when @crs<='' then 'lie'
192         when @crs<='' then 'lin'
193         when @crs<='' then 'ling'
194         when @crs<='' then 'liu'
195         when @crs<='' then 'long'
196         when @crs<='' then 'lou'
197         when @crs<='' then 'lu'
198         when @crs<='' then 'lv'
199         when @crs<='' then 'luan'
200         when @crs<='' then 'lue'
201         when @crs<='' then 'lun'
202         when @crs<='' then 'luo'
203         when @crs<='' then 'ma'
204         when @crs<='' then 'mai'
205         when @crs<='' then 'man'
206         when @crs<='' then 'mang'
207         when @crs<='' then 'mao'
208         when @crs<='' then 'me'
209         when @crs<='' then 'mei'
210         when @crs<='' then 'men'
211         when @crs<='' then 'meng'
212         when @crs<='' then 'mi'
213         when @crs<='' then 'mian'
214         when @crs<='' then 'miao'
215         when @crs<='' then 'mie'
216         when @crs<='' then 'min'
217         when @crs<='' then 'ming'
218         when @crs<='' then 'miu'
219         when @crs<='' then 'mo'
220         when @crs<='' then 'mou'
221         when @crs<='' then 'mu'
222         when @crs<='' then 'na'
223         when @crs<='' then 'nai'
224         when @crs<='' then 'nan'
225         when @crs<='' then 'nang'
226         when @crs<='' then 'nao'
227         when @crs<='' then 'ne'
228         when @crs<='' then 'nei'
229         when @crs<='' then 'nen'
230         when @crs<='' then 'neng'
231         when @crs<='' then 'ni'
232         when @crs<='' then 'nian'
233         when @crs<='' then 'niang'
234         when @crs<='' then 'niao'
235         when @crs<='' then 'nie'
236         when @crs<='' then 'nin'
237         when @crs<='' then 'ning'
238         when @crs<='' then 'niu'
239         when @crs<='' then 'nong'
240         when @crs<='' then 'nou'
241         when @crs<='' then 'nu'
242         when @crs<='' then 'nv'
243         when @crs<='' then 'nue'
244         when @crs<='' then 'nuan'
245         when @crs<='' then 'nuo'
246         when @crs<='' then 'o'
247         when @crs<='' then 'ou'
248         when @crs<='' then 'pa'
249         when @crs<='' then 'pai'
250         when @crs<='' then 'pan'
251         when @crs<='' then 'pang'
252         when @crs<='' then 'pao'
253         when @crs<='' then 'pei'
254         when @crs<='' then 'pen'
255         when @crs<='' then 'peng'
256         when @crs<='' then 'pi'
257         when @crs<='' then 'pian'
258         when @crs<='' then 'piao'
259         when @crs<='' then 'pie'
260         when @crs<='' then 'pin'
261         when @crs<='' then 'ping'
262         when @crs<='' then 'po'
263         when @crs<='' then 'pou'
264         when @crs<='' then 'pu'
265         when @crs<='' then 'qi'
266         when @crs<='' then 'qia'
267         when @crs<='' then 'qian'
268         when @crs<='' then 'qiang'
269         when @crs<='' then 'qiao'
270         when @crs<='' then 'qie'
271         when @crs<='' then 'qin'
272         when @crs<='' then 'qing'
273         when @crs<='' then 'qiong'
274         when @crs<='' then 'qiu'
275         when @crs<='' then 'qu'
276         when @crs<='' then 'quan'
277         when @crs<='' then 'que'
278         when @crs<='' then 'qun'
279         when @crs<='' then 'ran'
280         when @crs<='' then 'rang'
281         when @crs<='' then 'rao'
282         when @crs<='' then 're'
283         when @crs<='' then 'ren'
284         when @crs<='' then 'reng'
285         when @crs<='' then 'ri'
286         when @crs<='' then 'rong'
287         when @crs<='嶿' then 'rou'
288         when @crs<='' then 'ru'
289         when @crs<='' then 'ruan'
290         when @crs<='' then 'rui'
291         when @crs<='' then 'run'
292         when @crs<='' then 'ruo'
293         when @crs<='' then 'sa'
294         when @crs<='' then 'sai'
295         when @crs<='' then 'san'
296         when @crs<='' then 'sang'
297         when @crs<='' then 'sao'
298         when @crs<='' then 'se'
299         when @crs<='' then 'sen'
300         when @crs<='' then 'seng'
301         when @crs<='' then 'sha'
302         when @crs<='' then 'shai'
303         when @crs<='' then 'shan'
304         when @crs<='' then 'shang'
305         when @crs<='' then 'shao'
306         when @crs<='' then 'she'
307         when @crs<='' then 'shen'
308         when @crs<='' then 'sheng'
309         when @crs<='' then 'shi'
310         when @crs<='' then 'shou'
311         when @crs<='' then 'shu'
312         when @crs<='' then 'shua'
313         when @crs<='' then 'shuai'
314         when @crs<='' then 'shuan'
315         when @crs<='' then 'shuang'
316         when @crs<='' then 'shui'
317         when @crs<='' then 'shun'
318         when @crs<='' then 'shuo'
319         when @crs<='' then 'si'
320         when @crs<='' then 'song'
321         when @crs<='' then 'sou'
322         when @crs<='' then 'su'
323         when @crs<='' then 'suan'
324         when @crs<='' then 'sui'
325         when @crs<='' then 'sun'
326         when @crs<='' then 'suo'
327         when @crs<='' then 'ta'
328         when @crs<='' then 'tai'
329         when @crs<='' then 'tan'
330         when @crs<='' then 'tang'
331         when @crs<='' then 'tao'
332         when @crs<='' then 'te'
333         when @crs<='' then 'teng'
334         when @crs<='' then 'ti'
335         when @crs<='' then 'tian'
336         when @crs<='' then 'tiao'
337         when @crs<='' then 'tie'
338         when @crs<='' then 'ting'
339         when @crs<='' then 'tong'
340         when @crs<='' then 'tou'
341         when @crs<='' then 'tu'
342         when @crs<='' then 'tuan'
343         when @crs<='' then 'tui'
344         when @crs<='' then 'tun'
345         when @crs<='' then 'tuo'
346         when @crs<='' then 'wa'
347         when @crs<='' then 'wai'
348         when @crs<='' then 'wan'
349         when @crs<='' then 'wang'
350         when @crs<='' then 'wei'
351         when @crs<='' then 'wen'
352         when @crs<='' then 'weng'
353         when @crs<='' then 'wo'
354         when @crs<='' then 'wu'
355         when @crs<='' then 'xi'
356         when @crs<='' then 'xia'
357         when @crs<='' then 'xian'
358         when @crs<='' then 'xiang'
359         when @crs<='' then 'xiao'
360         when @crs<='' then 'xie'
361         when @crs<='' then 'xin'
362         when @crs<='' then 'xing'
363         when @crs<='' then 'xiong'
364         when @crs<='' then 'xiu'
365         when @crs<='' then 'xu'
366         when @crs<='' then 'xuan'
367         when @crs<='' then 'xue'
368         when @crs<='' then 'xun'
369         when @crs<='' then 'ya'
370         when @crs<='' then 'yan'
371         when @crs<='' then 'yang'
372         when @crs<='' then 'yao'
373         when @crs<='' then 'ye'
374         when @crs<='' then 'yi'
375         when @crs<='' then 'yin'
376         when @crs<='' then 'ying'
377         when @crs<='' then 'yo'
378         when @crs<='' then 'yong'
379         when @crs<='' then 'you'
380         when @crs<='' then 'yu'
381         when @crs<='' then 'yuan'
382         when @crs<='' then 'yue'
383         when @crs<='' then 'yun'
384         when @crs<='' then 'za'
385         when @crs<='' then 'zai'
386         when @crs<='' then 'zan'
387         when @crs<='' then 'zang'
388         when @crs<='' then 'zao'
389         when @crs<='' then 'ze'
390         when @crs<='' then 'zei'
391         when @crs<='' then 'zen'
392         when @crs<='' then 'zeng'
393         when @crs<='' then 'zha'
394         when @crs<='' then 'zhai'
395         when @crs<='' then 'zhan'
396         when @crs<='' then 'zhang'
397         when @crs<='' then 'zhao'
398         when @crs<='' then 'zhe'
399         when @crs<='' then 'zhen'
400         when @crs<='' then 'zheng'
401         when @crs<='' then 'zhi'
402         when @crs<='' then 'zhong'
403         when @crs<='' then 'zhou'
404         when @crs<='' then 'zhu'
405         when @crs<='' then 'zhua'
406         when @crs<='' then 'zhuai'
407         when @crs<='' then 'zhuan'
408         when @crs<='' then 'zhuang'
409         when @crs<='' then 'zhui'
410         when @crs<='' then 'zhun'
411         when @crs<='' then 'zhuo'
412         when @crs<='' then 'zi'
413         when @crs<='' then 'zong'
414         when @crs<='' then 'zou'
415         when @crs<='' then 'zu'
416         when @crs<='' then 'zuan'
417         when @crs<='' then 'zui'
418         when @crs<='' then 'zun'
419         when @crs<='' then 'zuo'
420         else  @crs end+' '+@re,@strlen=@strlen-1 
421    end
422  return(@re)
423 end
424 
425 go
426 
427 DECLARE @str VARCHAR(max)
428 SET @str= [dbo].[fn_getpy]('深圳')
429 PRINT(@str)
430 --获取汉字首字母
431 ALTER   function   [dbo].[fn_getpy](@str   nvarchar(100)) 
432 returns   nvarchar(4000) 
433 as 
434 begin 
435 declare   @str_len   int,@result   nvarchar(4000) ,@crs nvarchar(1)
436 set @str_len=len(@str)
437 set @result= ' ' 
438     while   @str_len> 0 
439     begin 
440 set  @crs=substring(@str,@str_len,1)
441  
442    select  @str_len=@str_len-1,@result=
443      case  
444      when @crs>='' then 'Z'
445      when @crs>='' then 'Y'
446      when @crs>='' then 'X'
447      when @crs>='' then 'W'
448      when @crs>='' then 'T'
449      when @crs>='' then 'S'
450      when @crs>='' then 'R'
451      when @crs>='' then 'Q'
452      when @crs>='' then 'P'
453      when @crs>='' then 'O'
454      when @crs>='' then 'N'
455      when @crs>='' then 'M'
456      when @crs>='' then 'L'
457      when @crs>='' then 'K'
458      when @crs>='' then 'J'
459      when @crs>='' then 'H'
460      when @crs>='' then 'G'
461      when @crs>='' then 'F'
462      when @crs>='' then 'E'
463      when @crs>='' then 'D'
464      when @crs>='' then 'C'
465      when @crs>='' then 'B'
466      when @crs>='' then 'A'
467      else  @crs  end+@result
468     end 
469     return(@result) 
470 END
View Code

 

posted on 2015-01-19 15:48    阅读(615)  评论(0编辑  收藏  举报