标签:
批量插入100条记录
set nocount on declare @i int=1; while @i<=100 begin Insert into Client(id,ClientCode,ClientName,ClientGroup,stype,Contact,ClientTel,SendAddress) select @i+8,‘C‘+right(‘000000‘+CAST(@i as varchar),6),‘Customer‘+CAST(@i as varchar),‘B组‘,‘E帐‘, ‘小张‘+CAST(@i as varchar),‘00000000000‘,‘中国广东‘ set @i=@i+1 end go
《一些函数语法》
数字转换成字符串:把100转换成字符串
CAST(100 as varchar)
数字转换成字符串,并在前面补0,下面表示共6为数
right(‘000000‘+CAST(100 as varchar),6)
随机生成200以内的随机整数
select CAST(RAND()*200 as int)
随机生成个位数
select CHAR(ROUND(RAND() * 9+48,0))
生成有序字符串,前面是年月日时分秒,后三位是随机数
DECLARE @rand NVARCHAR(16) set @rand = REPLACE(CONVERT(NVARCHAR(16), GETDATE(), 120), ‘-‘, ‘‘); SET @rand = REPLACE(@rand, ‘ ‘, ‘‘); SET @rand = REPLACE(@rand, ‘:‘, ‘‘); SET @rand = @rand + CAST(FLOOR ((RAND() * 900 + 100)) AS NVARCHAR(3)); PRINT @rand
标签:
原文地址:http://www.cnblogs.com/Sukie-s-home/p/5216903.html