MSSQLÓÐ ÀàËÆÓÚ SPLITµÄº¯ÊýÂð£¿
ÈçÌâ- -¡«
ÎÒÓÐÕâô¸ö¶«Î÷
Ò»¸ö
×Ö·û´®ÈçÏÂËùʾ
1,2,3,4,5
È»ºóÎÒ
ÐèҪѻ·µÄ°Ñ ÕâЩÊý¾Ý²åÈëµ½Êý¾Ý¿âÖÐ
ÎÒ¸ÃÔõô×ö£¿
http://blog.csdn.net/htl258/archive/2009/09/09/4533846.aspx
SQL code:
ÎÒÏÖÔÚÓÐÒ»×Ö¶ÎֵΪ:a,b,c
·Ö¸ô·ûΪ¶ººÅ.
ÎÒÏÖÔÚÏëʵÏÖÄ¿µØֵΪ:
×Ö¶Î:
id name
1 a
2 b
3 c
ÔÚSQLÖÐզʵÏÖÄØ?
declare @str varchar(8000)
set @str = 'a1,b1,c2,d1,e3,f5'
set @str = 'select name='''+replace(@str,',',''''+' union all select ''')+''''
exec(@str)
¿ÉÒÔ×Ô¼º´´½¨Ò»¸öº¯Êý
SQL code:
create function f_split(@str varchar(8000),@StrSeprate varchar(10))
returns @temp table(a varchar(100))
as
begin
declare @i int
set @str=rtrim(ltrim(@str))
set @i=charindex(@StrSeprate,@str)
while @i>=1
begin
insert @temp values(left(@str,@i-1))
set @str=substring(@str,@i+1,len(@str)-@i) --µ±È»,ÕâÀïÄúÒ²¿ÉÒÔ¸ÄдΪSTUFF,¿ÉÒÔ×Ô¼ºÊÔןÄдһÏÂ
set @i=charindex(@StrSeprate,@str)
end
if @str<>'\'
insert @temp values(@str)
return
end
--Ó÷¨£ºselect * from dbo.f_split('A:B:C:D:E',':')
ÇëÎÊÒ»ÏÂ
Èç¹ûÏë²åÈëÖ¸¶¨ÁÐ
¸ÃÈçºÎ×ö£¿
--ÕâÖÖ·½Ê½2000ÓÃÑ»
Ïà¹ØÎÊ´ð£º
Ö÷»ú
¿Í»§»úc1,c2,c3,c4,c5............
ÒªÇóÈçºÎ±£Ö¤¿Í»§»úÏòÖ÷»úÌá½»Êý¾Ý¾¡Á¿ÊµÊ±.¿ìËÙ.ÍêÕû
Ö±½ÓÓÃinsert ʱ,ËøסÖ÷»úµÄ±í.ËùÒÔ´Ë·½·¨²»¿ÉÐÐ
Çë¸ßÊÖÖ§ÕÐ..
Èç¹ûÖ»²åÈë¶ø²»¶Á£¬Óõ͸ôÀ뼶±ð
Äã²åÄãµÄ,Ëû²å ......
ÓÐÒ»¸öÊý¾Ý¿âÀïÖ»ÓÐ2WÌõÊý¾Ý²»µ½£¬È´ÓÐ500MÄÇô´ó,Ôõô»ØÊ°¡£¿ÊÇACCESSµÄÊý¾Ý¿â¡£ºóÀ´ÎÒ°ÑACCESSµ¼Èëµ½MSSQLÖУ¬Ò²Õ¼ÓÃÁË500M×óÓҵĿռ䣬Èç¹ûѹËõÊý¾Ý¿âÄØ£¿Çë¸ßÊÖÖ¸µã
ѹËõÊý¾Ý¿â£¿ÄÜ×öµ½Ã´...
ÆÚ´ý¸ßÈËÖ¸µã ÎÒ ......
Ò»ÕÅ±í£¬×ֶηÖΪid,time1,time2,time3,time4,time5
ÇëÎÊÎÒÓ¦¸ÃÈçºÎÑ¡ÔñIDΪ1µÄÄÇÌõ¼Ç¼ÖÐtimeʱ¼ä×îСµÄÖµÄØ£¿
UP!
[code=SQL][/code]select min(t) from
(select time1 as t from t1 where id ......
ÎÒÏëÎÊÏÂÐéÄâÖ÷»úÔËÓªÉ̵ÄMSSQL¿Õ¼ä¿É²»¿ÉÒÔÔ¶³ÌÁ¬½Ó£¿
¾ÍÊÇ˵ÔÚÎҵĻúÆ÷ÉÏÄܲ»ÄÜÓÃSSMSÁ¬½ÓËûµÄ·þÎñÆ÷
Èç¹ûÓÐÇë¸æËßÎÒÔËÓªÉ̵ĵØÖ·£¬Ð»Ð»£¡
ÔËÓªÉ̵ĵØÖ·½ÐÔËÓªÉ̸æËßÄ㣬¹Ø¼üµÄÊÇËû³ýÁËÔÊÐíÄãµÄ»úÆ÷Á¬½ÓÍ⣬»¹µ ......
·´ÕýÎÒÊǾ³£·Ö²»Çå¡¡
¼ÌÐøÉ¢·Ö
µÚÒ»¸ö±ÕÔ´£¬µÚ¶þ¸ö¿ªÔ´£¬µÚÈý¸öûŮÈËÔµ¡¡
LZÄ㻹ÓпÉÓ÷Öô£¿
ÒýÓÃ
LZÄ㻹ÓпÉÓ÷Öô£¿
5·Ö
ÒýÓÃ
µÚÒ»¸ö±ÕÔ´£¬µÚ¶þ¸ö¿ªÔ´£¬µÚÈý¸öûŮÈËÔµ¡¡
ÓÐÒâ˼¡£¿´±êÌ ......