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

SQLÖÐcase whenµÄÁ½ÖÖʹÓ÷½·¨Ê¾Àý

Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
         WHEN '1' THEN 'ÄÐ'
         WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
         WHEN sex = '2' THEN 'Å®'
ELSE 'ÆäËû' END
ÕâÁ½ÖÖ·½Ê½£¬¿ÉÒÔʵÏÖÏàͬµÄ¹¦ÄÜ¡£¼òµ¥Caseº¯ÊýµÄд·¨Ïà¶Ô±È½Ï¼ò½à£¬µ«ÊǺÍCaseËÑË÷º¯ÊýÏà±È£¬¹¦ÄÜ·½Ãæ»áÓÐЩÏÞÖÆ£¬±ÈÈçдÅжÏʽ¡£
»¹ÓÐÒ»¸öÐèҪעÒâµÄÎÊÌ⣬Caseº¯ÊýÖ»·µ»ØµÚÒ»¸ö·ûºÏÌõ¼þµÄÖµ£¬Ê£ÏµÄCase²¿·Ö½«»á±»×Ô¶¯ºöÂÔ¡£
--±ÈÈç˵£¬ÏÂÃæÕâ¶ÎSQL£¬ÄãÓÀÔ¶ÎÞ·¨µÃµ½“µÚ¶þÀà”Õâ¸ö½á¹û
CASE WHEN col_1 IN ( 'a', 'b') THEN 'µÚÒ»Àà'
         WHEN col_1 IN ('a')       THEN 'µÚ¶þÀà'
ELSE'ÆäËû' END
ÏÂÃæÎÒÃÇÀ´¿´Ò»Ï£¬Ê¹ÓÃCaseº¯Êý¶¼ÄÜ×öЩʲôÊÂÇé¡£
Ò»£¬ÒÑÖªÊý¾Ý°´ÕÕÁíÍâÒ»ÖÖ·½Ê½½øÐзÖ×飬·ÖÎö¡£
ÓÐÈçÏÂÊý¾Ý:(ΪÁË¿´µÃ¸üÇå³þ£¬ÎÒ²¢Ã»ÓÐʹÓùú¼Ò´úÂ룬¶øÊÇÖ±½ÓÓùú¼ÒÃû×÷ΪPrimary Key)
¹ú¼Ò£¨country£©    ÈË¿Ú£¨population£©
Öйú    600
ÃÀ¹ú    100
¼ÓÄô󠠠 100
Ó¢¹ú    200
·¨¹ú    300
ÈÕ±¾    250
µÂ¹ú    200
Ä«Î÷¸ç    50
Ó¡¶È    250
¸ù¾ÝÕâ¸ö¹ú¼ÒÈË¿ÚÊý¾Ý£¬Í³¼ÆÑÇÖ޺ͱ±ÃÀÖÞµÄÈË¿ÚÊýÁ¿¡£Ó¦¸ÃµÃµ½ÏÂÃæÕâ¸ö½á¹û¡£
ÖÞ    ÈË¿Ú
ÑÇÖÞ    1100
±±ÃÀÖÞ    250
ÆäËû    700
ÏëÒª½â¾öÕâ¸öÎÊÌ⣬Äã»áÔõô×ö£¿Éú³ÉÒ»¸ö´øÓÐÖÞCodeµÄView£¬ÊÇÒ»¸ö½â¾ö·½·¨£¬µ«ÊÇÕâÑùºÜÄѶ¯Ì¬µÄ¸Ä±äͳ¼ÆµÄ·½Ê½¡£
Èç¹ûʹÓÃCaseº¯Êý£¬SQL´úÂëÈçÏÂ:
SELECT SUM(population),
        CASE country
                WHEN 'Öйú'     THEN 'ÑÇÖÞ'
                WHEN '


Ïà¹ØÎĵµ£º

sql 2005 ´æ´¢¹ý³Ì·ÖÒ³ java ´úÂë

 create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',         
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ ......

[SQL Server]¹ØÓÚ¶Ôʱ¼ä´ÁtimestampÀí½â

Ò»Ö±¶Ôʱ¼ä´ÁµÄ¸ÅÄîÄ£ºý£¬²¢ÇÒÍøÉÏÒ²ÓкܶàÅóÓÑÒ²¶¼ÎóÈÏΪ£ºÊÇÒ»¸öʱ¼ä×ֶΣ¬Ã¿´ÎÔö¼ÓÊý¾Ýʱ£¬ÌîÈ뵱ǰµÄʱ¼äÖµ¡£µ¼ÖÂÒ²Îóµ¼Á˺ܶàÅóÓÑ¡£
 
Õâ´Î¿´Á˺ܶà×ÊÁÏ£¬¾ÀÕýÒ»ÏÂÕâ¸ö´íÎó£¬×Ô¼ºÒ²¸ãÇå³þ£ºÊý¾Ý¿âÖÐ×Ô¶¯Éú³ÉµÄΨһ¶þ½øÖÆÊý×Ö£¬Óëʱ¼äºÍÈÕÆÚÎ޹صģ¬ ͨ³£ÓÃ×÷¸ø±íÐмӰ汾´ÁµÄ»úÖÆ¡£´æ´¢´óСΪ 8 ¸ö×Ö½Ú¡£
&nbs ......

Êý¾Ý¿âÃüÃû¹æ·¶£¨ÊÊÓÃSQL Server£©

Éè¼ÆÔ­Ôò
 
·ûºÅÈý´ó·¶Ê½£¨Ã¿Ò»Áбí´ïÒ»¸öÒâ˼£¬Ã¿Ò»Ðдú±íÒ»¸öʵÀý/ÿһÐÐÓÐΨһ¼ü/±íÄÚûÓÐÆäËü±íµÄ·ÇÖ÷¼üÐÅÏ¢£©
 
ÿ¸ö±íÓ¦¸ÃÓеÄ3¸öÓÐÓÃ×ֶΣ¨¼Ç¼´´½¨»ò¸üÐÂʱ¼ä/¼Ç¼´´½¨Õß/¼Ç¼°æ±¾£©
 
±ÜÃâ±£Áô×Ö
 
±íÓ¦±ÜÃâ¿ÉΪ¿ÕµÄÁÐ


 
ÃüÃû¹æ·¶
 
±í
±íÃûÈçOr ......

Õë¶Ô SAP Êý¾Ý¿âά»¤ SQL Server µÄÊ®´ó×î¼Ñʵ¼ù


×÷Õß
£º
Takayuki Hoshino
׫¸åÈË
£º
Juergen Thomas
¼¼
Êõ
ÉóÔÄÈË
£º
Sanjay Mishra
SQL Server Ϊ SAP Ó¦ÓóÌÐòÌṩÁË׿ԽµÄÊý¾Ý¿âƽ̨¡£ÏÂÁн¨Òé¸ÅÊöÁËÕë¶Ô SAP ʵÏÖά»¤ SQL Server Êý¾Ý¿âµÄ×î¼Ñ×ö·¨¡£
ÿÌìÖ´ÐÐÍêÕûÊý¾Ý¿â±¸·Ý
´Ó
¼¼Êõ½Ç¶ÈÀ´Ëµ£¬Áª»ú±¸·Ý SAP Êý¾Ý¿â²»³ÉÎÊÌâ¡£ÕâÒâζ×Å£¬×îÖ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ