Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Find a T-SQL statement to realize the data of multiple fields of type integer-to-char(n).
Find a T-SQL statement to realize the data of multiple fields of type integer-to-char(n).
begin

Declare @a 1 int, @a2 int, @a3 int, @a4 int.

Declare @result char(8)

Set @ a1=1+cast (rand () * 33asin)-1-33 random number.

Set @ a2 =1+cast (rand () * 33asin)-1-33 random number.

Set @ a3 =1+cast (rand () * 33asin)-1-33 random number.

Set @ a4 =1+cast (rand () * 33asin)-1-33 random number.

select @result=replicate('0 ',2-len(cast(@ a 1 as varchar(2)))+cast(@ a 1 as varchar(2))+replicate(' 0 ',2-len(cast(@a2 as varchar(2)))

+cast(@ a2 as varchar(2))+replicate(' 0 ',2-len(cast(@a3 as varchar(2))。

Print' @ result is'+@ result-output @ result.

Insert tb_num46 (field 1, field 2, ..., num4).

Values (contents of field 1, contents of field 2, ..., @result)- Insert the result of @ result.

end