Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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×¢Èë¹¥»÷£¨Ï£© ²ÎÊý»¯sql

ÉÏһƪдµÄsql×¢ÈëµÄ»ù±¾Ô­Àí£¬±¾À´Òª½Ó×ÅдÕâƪµÄ£¬µ«ÊÇÓÉÓÚʱ¼äµÄÔ­ÒòһֱûÓÐд³É£¬½ñÌìÊÇÎåÒ»¼ÙÆÚ£¬×ÜËãÊÇÄܳé¿ÕддÁË¡£
×÷Ϊһ¸ö³ÌÐòÔ±£¬·À·¶sql×¢ÈëµÄµÚÒ»ÏßÊÇÓÉÎÒÃÇÀ´ÊØ»¤µÄ£¬Ö»ÒªÎÒÃÇÔÚ³ÌÐòÖÐÁôÉÙÐíµÄ©¶´£¬¾Í»á¸ø³ÌÐòÔöÇ¿°²È«ÌØÐÔ¡£ËùÒÔÎÒÃÇÒª×öµÄÊÇҪд°²È«µÄ³ÌÐò£¬·ÀÖ¹sql×¢ÈëÔÚ³ÌÐòÌåÏÖÔÚ²»ÒªÆ´½Ósql×Ö·û´®£¬ ......

SQL Server ϵͳȫ¾Ö±äÁ¿

SQL Server ϵͳȫ¾Ö±äÁ¿
@@CONNECTIONS
·µ»Ø×ÔÉÏ´ÎÆô¶¯ÒÔÀ´Á¬½Ó»òÊÔͼÁ¬½ÓµÄ´ÎÊý¡£
@@CURSOR_ROWS
·µ»ØÁ¬½ÓÉÏ×îºó´ò¿ªµÄÓαêÖе±Ç°´æÔڵĺϸñÐеÄÊýÁ¿(·µ»Ø±»´ò¿ªµÄÓαêÖл¹Î´±»¶ÁÈ¡µÄÓÐЧÊý¾ÝÐеÄÐÐÊý)
@@DATEFIRST
·µ»ØÿÖܵÚÒ»ÌìµÄÊý×Ö
@@ERROR
·µ»Ø×îºóÖ´ÐеÄSQL Óï¾äµÄ´íÎó´úÂë¡£
@@FETCH_STATUS
·µ»Ø ......

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

Êý¾Ý¿âʵÀý½á¹¹ ÊÂÎñÒ»ÖÂÐÔ(Transactional Consistency)ºÍ»ùÓÚʱ¼äµãµÄ»Ö¸´(Point-in-time Recovery) ϵͳԪÊý¾Ý
topÊý¾Ý¿âʵÀý½á¹¹
µ±OracleʵÀýÆô¶¯Ö®ºó£¬Ëù¿´µ½µÄ¾ÍÊÇÔÚ·þÎñÆ÷ÄÚ´æÉϵÄÒ»¸ö¸ö²»Í¬ÄÚ´æ¿é¼ÓÉϲúÉúµÄÓëÕâЩÄÚ´æ½»»¥µÄºǫ́½ø³Ì¡£OracleÎĵµ½«ÕâЩÄÚ´æ½á¹¹ºÍ½ø³ÌÊյĺÜÏêϸ¡£
ÓÉOracleʵÀýËùÕ¼ÓõÄÄÚ´æ¿é³ ......

SQL ServerÖÐtimestamp£¨Ê±¼ä´Á£©


SQL ServertimestampÊý¾ÝÀàÐÍÓëʱ¼äºÍÈÕÆÚÎ޹ء£SQL ServertimestampÊǶþ½øÖÆÊý×Ö£¬Ëü±íÃ÷Êý¾Ý¿âÖÐÊý¾ÝÐ޸ķ¢ÉúµÄÏà¶Ô˳Ðò¡£ÊµÏÖtimestampÊý¾ÝÀàÐÍ×î³õÊÇΪÁËÖ§³Ö SQL Server »Ö¸´Ëã·¨¡£Ã¿´ÎÐÞ¸Äҳʱ£¬¶¼»áʹÓõ±Ç°µÄ @@DBTS Öµ¶ÔÆä×öÒ»´Î±ê¼Ç£¬È»ºó @@DBTS ¼Ó1¡£ÕâÑù×ö×ãÒÔ°ïÖú»Ö¸´¹ý³ÌÈ·¶¨Ò³Ð޸ĵÄÏà¶Ô´ÎÐò£¬µ«ÊÇtimest ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ