--(此函数部分思路参考了CSDN上大力的转换函数)--邹建2005.01(引用请保留此信息)--*/Go--创建函数create function SBC2DBC( @str nvarchar(4000), --要转换的字符串 @flag bit --转换标志,0转换成半角,1转换成全角)returns nvarchar(4000) as begin declare @pat nvarchar(8),@step int,@i int,@spc int if @flag=0 select @pat=N'%[!-~]%',@step=-65248,@str=replace(@str,N' ',N' ') else select @pat=N'%[!-~]%',@step=65248,@str=replace(@str,N' ',N' ') set @i=patindex(@pat collate latin1_general_bin,@str) while @i>0 select @str=replace(@str,substring(@str,@i,1),nchar(unicode(substring(@str,@i,1))+@step)) ,@i=patindex(@pat collate latin1_general_bin,@str) return(@str) end --测试示例select dbo.SBC2DBC('~~~~ca!b',1) --运行结果/*~~~~ca!b*/ --附半角全角表/*ASCII 全角字符 Unicode 半角字符 Unicode 0x20 " "空格U+3000 " "空格U+00200x21 !U+ff01 ! U+00210x22 "U+ff02 " U+00220x23 #U+ff03 # U+00230x24 $U+ff04 $ U+00240x25 %U+ff05 % U+00250x26 &U+ff06 & U+00260x27 'U+ff07 ' U+00270x28 (U+ff08 ( U+00280x29 )U+ff09 ) U+00290x2a *U+ff0a * U+002a0x2b +U+ff0b + U+002b0x2c ,U+ff0c , U+002c0x2d -U+ff0d - U+002d0x2e .U+ff0e . U+002e0x2f /U+ff0f / U+002f0x30 0U+ff10 0 U+00300x31 1U+ff11 1 U+00310x32 2U+ff12 2 U+00320x33 3U+ff13 3 U+00330x34 4U+ff14 4 U+00340x35 5U+ff15 5 U+00350x36 6U+ff16 6 U+00360x37 7U+ff17 7 U+00370x38 8U+ff18 8 U+00380x39 9U+ff19 9 U+00390x3a :U+ff1a : U+003a0x3b ;U+ff1b ; U+003b0x3c <U+ff1c < U+003c0x3d =U+ff1d = U+003d0x3e >U+ff1e > U+003e0x3f ?U+ff1f ? U+003f0x40 @U+ff20 @ U+00400x41 AU+ff21 A U+00410x42 BU+ff22 B U+00420x43 CU+ff23 C U+00430x44 DU+ff24 D U+00440x45 EU+ff25 E U+00450x46 FU+ff26 F U+00460x47 GU+ff27 G U+00470x48 HU+ff28 H U+00480x49 IU+ff29 I U+00490x4a JU+ff2a J U+004a0x4b KU+ff2b K U+004b0x4c LU+ff2c L U+004c0x4d MU+ff2d M U+004d0x4e NU+ff2e N U+004e0x4f OU+ff2f O U+004f0x50 PU+ff30 P U+00500x51 QU+ff31 Q U+00510x52 RU+ff32 R U+00520x53 SU+ff33 S U+00530x54 TU+ff34 T U+00540x55 UU+ff35 U U+00550x56 VU+ff36 V U+00560x57 WU+ff37 W U+00570x58 XU+ff38 X U+00580x59 YU+ff39 Y U+00590x5a ZU+ff3a Z U+005a0x5b [U+ff3b [ U+005b0x5c \U+ff3c / U+005c0x5d ]U+ff3d ] U+005d0x5e ^U+ff3e ^ U+005e0x5f _U+ff3f _ U+005f0x60 `U+ff40 ` U+00600x61 aU+ff41 a U+00610x62 bU+ff42 b U+00620x63 cU+ff43 c U+00630x64 dU+ff44 d U+00640x65 eU+ff45 e U+00650x66 fU+ff46 f U+00660x67 gU+ff47 g U+00670x68 hU+ff48 h U+00680x69 iU+ff49 i U+00690x6a jU+ff4a j U+006a0x6b kU+ff4b k U+006b0x6c lU+ff4c l U+006c0x6d mU+ff4d m U+006d0x6e nU+ff4e n U+006e0x6f oU+ff4f o U+006f0x70 pU+ff50 p U+00700x71 qU+ff51 q U+00710x72 rU+ff52 r U+00720x73 sU+ff53 s U+00730x74 tU+ff54 t U+00740x75 uU+ff55 u U+00750x76 vU+ff56 v U+00760x77 wU+ff57 w U+00770x78 xU+ff58 x U+00780x79 yU+ff59 y U+00790x7a zU+ff5a z U+007a0x7b {U+ff5b { U+007b0x7c |U+ff5c | U+007c0x7d }U+ff5d } U+007d0x7e ~U+ff5e ~ U+007e*/