SQLServerÅúÁ¿µ¹ÈëĿ¼Îļþ ÊÕ²Ø
¿ÉÒÔÓÃÀ©Õ¹´æ´¢¹ý³Ìxp_dirtree»ñÈ¡ÎļþÁÐ±í£¬ÓÃopenrowsetµ¹ÈëÊý¾Ýµ½¶þ½øÖÆ×ֶΡ£
openrowsetµÄÓ÷¨¿ÉÒԲο¼msdn
http://technet.microsoft.com/zh-cn/library/ms190312.aspx
Èç¹ûÎļþºÜ¶à£¬½¨Ò黹ÊÇÓóÌÐòµ¹ÈëÁË
if (object_id ('t_bulkResult' ) is not null )
drop table t_bulkResult
create table t_bulkResult (name varchar (1000 ), data image )
go
declare @d varchar (1000 )
set @d = 'c:\test\'
create table #tb (fName varchar (1000 ), d int , f int )
insert into #tb exec xp_dirtree @d , 1 , 1
delete from #tb where f <> 1
declare @ sql nvarchar (max )
select @ sql = isnull (@ sql , '' )+ 'insert into t_bulkResult select ''' +@d + fname + ''',* from openrowset(bulk N''' +@d + fName + ''', SINGLE_BLOB) b
'
from #tb a
exec sp_executesql @ sql
drop table #tb
select * from t_bulkResult
Ïà¹ØÎĵµ£º
ÒýÓÃ×Ôhttp://blog.163.com/xing_aixin/blog/static/3723550520088189201623/
ÍøÉÏÓкܶàSQL ServerÊý¾Ý¿â×ÖµäµÄSQLÓï¾ä£¬ÆßÁã°ËÂ䣬ÎÒÔÚ¹¤×÷ÕûÀíÁËÒ»ÏÂ˼·£¬×ܽáSQL´úÂëÈçÏ¡£Êý¾Ý¿â×Öµä°üÀ¨±í½á¹¹(·Ö2KºÍ2005)¡¢Ë÷ÒýºÍÖ÷¼ü. Íâ¼ü.Ô¼Êø.ÊÓͼ.º¯Êý.´æ´¢¹ý³Ì.´¥·¢Æ÷¡£¿ÉÒÔÔÚÆóÒµ¹ÜÀíÆ÷¡¢²éѯ·ÖÎöÆ÷Öмòµ¥Ö´ÐУ¬Ö±½ÓÁ˵±µ ......
MySQL:
SELECT column from table
ORDER BY RAND()
LIMIT 1
PostgreSQL:
SELECT column from table
ORDER BY RANDOM()
LIMIT 1
Microsoft SQL Server:
SELECT TOP 1 column from table
ORDER BY NEWID()
IBM DB2
SELECT column, RAND() as IDX
from table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY
Thanks Ti ......
SQL Server 2008 Administration Instant Reference
SQL Server 2005 Êý¾Ý¿â»ù´¡ÓëÓ¦Óü¼Êõ
Microsoft SQLServer 2005 Integration Services Step by Step
SQLServer 2005 Bible
SQL Server 2005 Êý¾Ý¿â·þÎñ¼Ü¹¹Éè ......
sqlserver2005Óйؼü×Öntile(x)ºÍover(partition by.. order by..)×Ó¾äÅäºÏ.
±ÈÈç»ñȡÿ¸ö±íµÄǰ10%¸ö×ֶΡ£
select id , name , colid , rn from (
select * , rn = ntile (10 )
over (partition by id order by colorder )
from syscolumns )t where rn = 1 ......