标签:
DECLARE @LN VARCHAR(300),@MN VARCHAR(200),@FN VARCHAR(200)
DECLARE @LN_N INT,@MN_N INT,@FN_N INT
SET @LN=‘李王张刘陈杨黄赵周吴徐孙朱马胡郭林何高梁郑罗宋谢唐韩曹许邓萧冯曾程蔡彭潘袁于董余苏叶吕魏蒋田杜丁沈姜范江傅钟卢汪戴崔任陆廖姚方金邱夏谭韦贾邹石熊孟秦阎薛侯雷白龙段郝孔邵史毛常万顾赖武康贺严尹钱施牛洪龚‘
SET @MN=‘德绍宗邦裕傅家積善昌世贻维孝友继绪定呈祥大正启仕执必定仲元魁家生先泽远永盛在人为任伐风树秀文光谨潭棰‘
SET @FN=‘丽云峰磊亮宏红洪量良梁良粮靓七旗奇琪谋牟弭米密祢磊类蕾肋庆情清青兴幸星刑‘
SET @LN_N=LEN(@LN)
SET @MN_N=LEN(@MN)
SET @FN_N=LEN(@FN)
DECLARE @TMP VARCHAR(1000),@I INT
SET @I=100
WHILE @I<1000000
BEGIN
SET @TMP=CAST(SUBSTRING(@LN,CAST(RAND()*@LN_N AS INT),1) AS VARCHAR)
SET @TMP=@TMP+CAST(SUBSTRING(@MN,CAST(RAND()*@MN_N AS INT),1) AS VARCHAR)
SET @TMP=@TMP+CAST(SUBSTRING(@FN,CAST(RAND()*@FN_N AS INT),1) AS VARCHAR)
INSERT INTO student(sno,sname)VALUES(‘2005‘+@I,@TMP)
SET @I=@I+1
end
---摘自互联网,若有侵犯,请留言!
在sql server中新建一个查询就能批量插入数据,以前总以为要写个存储过程才能批量插入呢...
cast和convert都是用于类型转换,功能相同,只是语法不同,cast更容易使用,而convert的优点是格式化日期和时间;
以下把http://www.cnblogs.com/davidgu/archive/2011/02/15/1955335.html中的实例搬过来,供自己学习
select CAST(‘123‘ as int) -- 123
select CONVERT(int, ‘123‘) -- 123
select CAST(123.4 as int) -- 123
select CONVERT(int, 123.4) -- 123
select CAST(‘123.4‘ as int)
select CONVERT(int, ‘123.4‘)
-- Conversion failed when converting the varchar value ‘123.4‘ to data type int.
select CAST(‘123.4‘ as decimal) -- 123
select CONVERT(decimal, ‘123.4‘) -- 123
select CAST(‘123.4‘ as decimal(9,2)) -- 123.40
select CONVERT(decimal(9,2), ‘123.4‘) -- 123.40
declare @Num money
set @Num = 1234.56
select CONVERT(varchar(20), @Num, 0) -- 1234.56
select CONVERT(varchar(20), @Num, 1) -- 1,234.56
select CONVERT(varchar(20), @Num, 2) -- 1234.5600
标签:
原文地址:http://www.cnblogs.com/QMM2008/p/5221152.html