ÎÒÏëÓÃÒ»ÌõSQLÏÔʾÕâÑùµÄ½á¹û
²»ÖªµÀÕâÑùµÄÒªÇóÄܲ»ÄÜʵÏÖ£¿
±ÈÈçÎÒÓÐÒ»ÕűíT1£¬ÀïÃæÖ»ÓÐÒ»¸ö×Ö¶Î1
ÀïÃæÓÐ100Ìõ¼Ç¼£¬ÈçÏÂËùʾ£º
×Ö¶Î1
A1
A2
A3
A4
...
A100
ÎÒÏëÓÃÒ»ÌõSQLÏÔʾÕâÑùµÄ½á¹û
µÚÒ»ÁÐ µÚ¶þÁÐ ... µÚÊ®ÁÐ
A1 A11 A91
A2 A12 A92
A3 A13 A93
... ... ...
A10 A20 A100
²»Öª¿É·ñʵÏÖ£¿µ±È»£¬Ò²²»Ò»¶¨·Ö³ÉÊ®ÁУ¬¿ÉÄÜÊÇÎåÁеȵȣ¬Çë¸ßÊִͽ̡£Ð»Ð»
--¼ÙÉè×ֶβ»´æÔÚÏàֵͬ.
select
max(case (px - 1) % 10 when 0 then ×Ö¶Î1 else '' end) [c1],
max(case (px - 1) % 10 when 1 then ×Ö¶Î1 else '' end) [c2],
max(case (px - 1) % 10 when 2 then ×Ö¶Î1 else '' end) [c3],
max(case (px - 1) % 10 when 3 then ×Ö¶Î1 else '' end) [c4],
max(case (px - 1) % 10 when 4 then ×Ö¶Î1 else '' end) [c5],
max(case (px - 1) % 10 when 5 then ×Ö¶Î1 else '' end) [c6],
max(case (px - 1) % 10 when 6 then ×Ö¶Î1 else '' end) [c7],
max(case (px - 1) % 10 when 7 then ×Ö¶Î1 else '' end) [c8],
max(case (px - 1) % 10 when 8 then ×Ö¶Î1 else '' end) [c9],
max(case (px - 1) % 10 when 9 then ×Ö¶Î1 else '' end) [c10]
from
(
select * , px = (select count(1) from t1 where ×Ö¶Î1 < t.×Ö¶Î1) + 1 from t1 t
) m
group by (px - 1) / 10
--Èç¹û×ֶδæÔÚÏàֵͬ.
--sql 2000ÐèҪʹÓÃÁÙʱ±í
select * , px = identity(int,1,1) into tmp from t1
select
max(case (px - 1) % 10 when 0 then ×Ö¶Î1 else '' end) [c1],
max(case (px - 1) % 10 when 1 then ×Ö¶Î1 else '' end) [c2],
max(case (px - 1) % 10 when 2 then ×Ö¶Î1 else '' end) [c3],
m
Ïà¹ØÎĵµ£º
SELECT * into newtable
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\aaaa.xls";User ID=Admin;Password=;Extended properties=Excel 11.0')...[Sheet1$]
/******* µ¼³öµ½excel
¡¡¡¡exec master..xp_cmdshell 'bcp settledb.dbo.shanghu out c:\temp1.xls -c -q -s"gnetdata/gnetdata" - ......
SQL Server ×èÖ¹Á˶Ô×é¼þ 'Ad Hoc Distributed Queries' µÄ STATEMENT'OpenRowset/OpenDatasource' µÄ·ÃÎÊ£¬ÒòΪ´Ë×é¼þÒÑ×÷Ϊ´Ë·þÎñÆ÷°²È«ÅäÖõÄÒ»²¿·Ö¶ø±»¹Ø±Õ¡£ÏµÍ³¹ÜÀíÔ±¿ÉÒÔͨ¹ýʹÓà sp_configure ÆôÓà 'Ad Hoc Distributed Queries'¡£ÓйØÆôÓà 'Ad Hoc Distributed Queries' µÄÏêϸÐÅÏ¢£¬Çë²ÎÔÄ SQL Server Áª»ú´ÔÊéÖÐ ......
Ç°²»¾Ã¿´µ½Í¬ÊÂÔÚÓÃSql Prompt3.9£¬¾õµÃÂù·½±ãµÄ¡£¸øÎÒÃÇд³ÌÐòÄÜʡϲ»ÉÙÁ¦Æø¡£·½±ã£¬sql´úÂë¿´ÆðÀ´ÓÖ¼ò½é¡£ÖµµÃÍƼö¡£http://www.red-gate.com/ÕâÊÇËüµÄ¹ÙÍø£¬ÊÇÒ»¿îÊշѵÄÈí¼þ¡£Õýʽ°æ±¾ÏÂÔØÏÂÀ´Ö»ÄÜʹÓÃ14Ìì¡£·Ï»°²»ËµÁË£¬ÏÈ¿´ÏÂЧ¹ûͼ£º
»¹²»´í°¡¡£
½ÓÏÂÀ´½éÉÜÏÂÆƽâµÄ·½·¨£¬Ïȵ½¹ÙÍø°Ñ×îаæ(ÏÖÔÚÒѾÊÇ3.9ÁË)ÏÂÏÂÀ ......
Èç¹ûÔÀ´µÄÊý¾Ý¿â¿ÉÓ㬷ÖÀëÊý¾Ý¿âºó£¬Ö»¸½¼ÓÊý¾ÝÎļþ£¬²»¸½¼ÓÈÕÖ¾
Èç¹û²»¿ÉÓã¬Ö»ÄÜÂýÂýµÈ»¹Ô²Ù×÷Íê³ÉÁË
ÈÕÖ¾ÎļþÌ«´óÁË£¬Ó¦¸Ã¶¨ÆÚÕûÀíÈÕÖ¾
--ѹËõÈÕÖ¾¼°Êý¾Ý¿âÎļþ´óС
&n ......
table a(id, type):
id type
----------------------------------
1 1
2 1
3 &n ......