1.upper()函数lower()完成字符串大小写的转换
eg. select * from article where upper(title) like '%'+upper(@title)+'%';
eg. select top 10 * from word w_rank = 1 order by newid()
3.sql server生成随机数(转载:http://blog.sina.com.cn/s/blog_49b531af0100o2e1.html)
- sqlserver虽然有rand()函数可以用,但单纯用rand()来获取随机数有很多限制,因为rand()生成的是类似0.747589267212168的随机小数,灵活处理一下就可以得到整数
- select
cast(ceiling(rand() int) --生成的数是N以内的证书* N) as - select
cast(ceiling(rand(checksum(newid()))*N) int)as 这个同上,但在批量操作时往往这个会更有用,如 - update
table 5set field=cast(ceiling(rand() * ) int)as 和update int)产生的效果就完全不同,前者虽然也是生成随机数了,但是所有table表里的field字段的数值都是一样的,而后者就各不相同,原理就是1是先生成随机数,然后再更新,2是更新每条记录前生成随机数。table set field=cast(ceiling(rand(checksum(newid()))*N) as - 将上面俩条语句中的ceiling换成floor就可以生成包含0的整数随机数。