Joke Collection Website - Cold jokes - Sql string inserts comma and replaces it.

Sql string inserts comma and replaces it.

-test environment MSSQL2008

-ABCDEFJHIJK transform 123456789 123 and so on.

-Make a watch

Create? Table? T

(

Val. varchar( 1000)

)

-Insert data

Insert? Become? t? Value ("ABC")

Insert? Become? t? Value ("ABA")

Insert? Become? t? Value ('abcdefghijklmnopqrstuvwxyz')

-Method 1 (string length is less than 2048)

Choice? Val, things (

(

Choice? ,'+Char((Ascii(Upper(Substring(val,number, 1)))- 1 1)% 9+49)?

From where? Master.dbo.spt_values

Where is it? Type='P '? And then what? Number? Between? 1? And then what? Aaron (val)?

For what? Xml? Path ("")

, 1, 1,'')?

From where? t?

-Method two?

Create? Function? fn_change(@A? Varchar(8000))

Return? Varchar(8000)

be like

begin

Declare? @Rst? Varchar(8000)=“

Declare? @ me? int= 1

What time? @ i & lt=LEN(@A)

begin

Settings? @Rst=@Rst+','+Char((Ascii(Upper(Substring(@ A,@I, 1)))- 1 1)% 9+49)?

Settings? @i=@i+ 1

end

Return? Stuff(@Rst, 1, 1,'')

end

-Inquiry

Choice? *,dbo.fn_change(Val)? From where? T