Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÇÉÓÃSQL PIVOTʵÏÖ»·¾³¼à²âÊý¾ÝµÄ¡°Êúºá¡±×ª»»


Ë®»·¾³¼à²âÊý¾Ý´æ´¢½á¹¹ÖÐÓÐÒ»ÖÖģʽ½Ð×ö"Êú±íģʽ"£¬¼´ÔÚ¼à²âÊý¾Ý±íÖУ¬Ä³¸öµãλÔÚij¸öʱ¼äµãÉϸ÷¼à²âÏîÄ¿µÄŨ¶È²â¶¨ÖµÔÚÎïÀí±íÖд洢ÔÚ¶àÌõ¼Ç¼ÖУ¬³ÊÊú×´·Ö²¼¡£¼à²âÊý¾Ý±íÖаüº¬²âµã´úÂë¡¢¼à²âʱ¼ä¡¢¼à²âÏîÄ¿´úÂ롢Ũ¶È²â¶¨ÖµµÈ£¬ËùÓмà²âÏîÄ¿µÄŨ¶È²â¶¨Öµ¶¼´æ´¢ÔÚͬһ¸ö×Ö¶ÎÖУ¬¼ÓÒÔ¼à²âÏîÄ¿´úÂë×÷ΪÇø·Ö×ֶΡ£
"Êú±íģʽ"µÄ×î´óÌصãÊÇÁé»î¡¢¾ßÓнϺõÄÀ©Õ¹ÐÔ¡£Õë¶ÔÐÂÔö¼à²âÒò×Ó£¬Ö»ÐèÒªÔÚ¼à²âÒò×Ó±àÂë±í½øÐÐά»¤£¬Ôö¼Óеļà²âÒò×Ó£¬¾ÍÄÜÂú×ãÊý¾Ý´æ´¢µÄÒªÇó¡£ÕâÖÖÉè¼Æģʽ·Ç³£ÊʺÏ×Ô¶¯¼à²âÕ¾ÒÔ¼°ÎÛȾԴ¼à²âÊý¾ÝµÄ´æ´¢¡£µ«ÊÇ"Êú±íģʽ"Ò²ÓÐһЩ²»×ãÖ®´¦£¬±ÈÈçÊý¾Ý¿É¶ÁÐÔ²»ºÃ£¬ÄÑÒÔ±í´ïij¸öµãλij¸öʱ¼äµãÉϵÄÕûÌåÊý¾ÝÇé¿ö£¬²»·ûºÏ´«Í³Ï°¹ßµÄ"ºá±í"Êý¾ÝÔĶÁ·½Ê½¡£ÈçºÎÈÃ"Êú±í"ת»»³É"ºá±í"ÊǺܶàÓ¦ÓÃϵͳÖж¼ÒªÓöµ½µÄÒ»¸öÎÊÌâ¡£
ÏÖ¼ÙÉèÓÐÒ»ÕÅÃû³ÆΪ"×Ô¶¯Õ¾¼à²âÊý¾ÝÈÕ¾ùÖµ±í" µÄÊý¾Ý±í£¬ÏêϸÊý¾ÝÈçÏ£º
²âµã´úÂë
Äê
ÔÂ
ÈÕ
¼à²âÏîÄ¿
ÎÛȾÎïŨ¶È
P001
2008
2
1
Éú»¯ÐèÑõÁ¿
298
P001
2008
2
1
×ÜÁ×
0.526
P001
2008
2
1
»¯Ñ§ÐèÑõÁ¿
414
P001
2008
2
1
°±µª
1.09
P002
2008
2
3
Éú»¯ÐèÑõÁ¿
198
P002
2008
2
3
×ÜÁ×
0.426
P002
2008
2
3
»¯Ñ§ÐèÑõÁ¿
314
P002
2008
2
3
×ܵª
3.71
   
ΪÁËÄܹ»½«Êý¾Ýת»»Îªºá±íÐÎʽ£¬Ê×ÏÈ£¬ÔÚSQL Server 2005£¨»ò2008£©Êý¾Ý¿âÖн¨Á¢´æ´¢¹ý³Ìusp_pivot¡£SQL´´½¨Óï¾äÈçÏ£º
   
CREATE PROC [dbo].[usp_pivot]
¡¡  @schema_name AS sysname¡¡¡¡  = N'dbo',-- ±í/ÊÓͼµÄ¼Ü¹¹
¡¡  @object_name AS sysname¡¡¡¡  = NULL, -- ±í/ÊÓͼµÄÃû³Æ
¡¡  @on_rows¡¡¡¡ AS sysname¡¡¡¡  = NULL, -- ·Ö×éÁÐ--¿ÉÒÔÊÇÒÔ,Ïà¸ôµÄ¶à¸öÁÐ
¡¡  @on_cols¡¡¡¡ AS sysname¡¡¡¡  = NULL, -- ÐýתÁÐ
¡¡  @agg_func¡¡  AS NVARCHAR(12) = N'MAX',-- ¾Û¼¯º¯Êý
¡¡  @agg_col¡¡¡¡ AS sysname¡¡¡¡  = NULL -- ͳ¼ÆÁÐ
AS
¡¡  DECLARE
¡¡  @object AS NVARCHAR(600),
¡¡  @sql¡¡¡¡ AS NVARCHAR(MAX),
¡¡  @cols¡¡  AS NVARCHAR(MAX),
¡¡  @newline AS NVARCHAR(2),
¡¡  @msg¡¡¡¡ AS NVARCHAR(500);
   
¡¡  SET @newline = NCHAR(13) + NCHAR(10);
¡¡  SET @object = QUOTENAME(@schema_name) + N'.'


Ïà¹ØÎĵµ£º

VS2005×Ô´øSQL ExpressÅäÖÃ

ÏÂÃæÊDzÙ×÷²½Ö裺
1. “·þÎñºÍÁ¬½ÓµÄÍâΧӦÓÃÅäÖÓ -¡·“±¾µØÁ¬½ÓºÍÔ¶³ÌÁ¬½Ó”-¡·“ͬʱʹÓÃTCP/IPºÍNamed Pipes“£»
2. “·þÎñÅäÖùÜÀíÆ÷”-¡·“ÍøÂçÅäÖÔ-¡·“SQL ExpressµÄЭÒé“-¡·“IPµØÖ·”£¬½«IpAll Tcp¶Ë¿Ú¸ÄΪ1433£»
3.  ÖØÆô·þ ......

Sql server 2000 µÄµÈ´ýÏìӦʱ¼ä

     Ç°Ò»¶Îʱ¼äÔÚά»¤Ò»¸öÀÏÏîÄ¿µÄʱºò·¢ÏÖ£¬ÔÚÖ´ÐÐÒ»¸ö½Ï´óµÄ´æ´¢¹ý³Ìʱ£¬×ÜÊDZ¨“³£¹æÍøÂç´íÎó£¬Çë¼ì²éÄúµÄÍøÂçÎĵµ”¡£ÔÚºóÐøµÄά»¤¼ì²éÖз¢ÏÖ£¬ÊÇÊÂÎﳬʱµ¼ÖÂÖ´ÐÐÖÐÖ¹µÄ¡£
     ÏÂÃæÊǵ÷Õû¹ý³Ì£º
      Ò»¡¢°ÑSQL SERVERµÄµÈ´ýÏìӦʱ¼ ......

Éî¶È¶Ô±ÈOracleÓëSQL Server——µÚÒ»²¿·Ö

²Ù×÷ϵͳµÄÖ§³Ö °æ±¾ºÍ·¢Ðаæ ʵÀý¡¢Êý¾Ý¿âºÍ±í¿Õ¼ä ʵÀýÃûºÍSID ϵͳÊý¾Ý¿âºÍϵͳ±í¿Õ¼ä
Ò»°ãµÄ¹«Ë¾Í¨³£»áÔÚËûÃǵÄÐÅϢϵͳ¼Ü¹¹ÖÐÒýÈë¶àÖÖÊý¾Ý¿âƽ̨£¬Í¬Ê±ÒýÈëÈýµ½ËÄÖÖ²»Í¬µÄRDBMS½â¾ö·½°¸µÄÖдóÐ͹«Ë¾Ò²²¢²»ÉÙ¼û£¬µ±È»ÕâЩ¹«Ë¾ÀïÃæµÄDBAÃÇͨ³£Ò²ÐèҪͬʱӵÓйÜÀí¶àÖÖ²»Í¬Æ½Ì¨µÄ¼¼ÄÜÁË¡£
Ö»ÔÚÒ»ÖÖƽ̨ÉÏÕ¹¿ª¹¤×÷µÄÊý¾Ý ......

sql server sysobjects xtypeÀàÐÍ

xtype  ´ú±íÀàÐÍ
C = CHECK Ô¼Êø
D = ĬÈÏÖµ»ò DEFAULT Ô¼Êø
F = FOREIGN KEY Ô¼Êø
L = ÈÕÖ¾
FN = ±êÁ¿º¯Êý
IF = ÄÚǶ±íº¯Êý
P = ´æ´¢¹ý³Ì
PK = PRIMARY KEY Ô¼Êø£¨ÀàÐÍÊÇ K£©
RF = ¸´ÖÆɸѡ´æ´¢¹ý³Ì
S = ϵͳ±í
TF = ±íº¯Êý
TR = ´¥·¢Æ÷
U = Óû§±í
UQ = UNIQUE Ô¼Êø£¨ÀàÐÍÊÇ K£©
V = ÊÓͼ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ