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

sqlÖÐCASEµÄÓ÷¨

 
À´Ô´:SQL°ïÖúÎĵµ
CASE
¼ÆËãÌõ¼þÁÐ±í²¢·µ»Ø¶à¸ö¿ÉÄܽá¹û±í´ïʽ֮һ¡£
CASE ¾ßÓÐÁ½ÖÖ¸ñʽ£º
¼òµ¥ CASE º¯Êý½«Ä³¸ö±í´ïʽÓëÒ»×é¼òµ¥±í´ïʽ½øÐбȽÏÒÔÈ·¶¨½á¹û¡£
CASE ËÑË÷º¯Êý¼ÆËãÒ»×é²¼¶û±í´ïʽÒÔÈ·¶¨½á¹û¡£
Á½ÖÖ¸ñʽ¶¼Ö§³Ö¿ÉÑ¡µÄ ELSE ²ÎÊý¡£
Óï·¨
¼òµ¥ CASE º¯Êý£º
CASE input_expression
    WHEN when_expression THEN result_expression
        [ ...n ]
    [
        ELSE else_result_expression
    END
CASE ËÑË÷º¯Êý£º
CASE
    WHEN Boolean_expression THEN result_expression
        [ ...n ]
    [
        ELSE else_result_expression
    END
²ÎÊý
input_expression
ÊÇʹÓüòµ¥ CASE ¸ñʽʱËù¼ÆËãµÄ±í´ïʽ¡£Input_expression ÊÇÈκÎÓÐЧµÄ Microsoft® SQL Server™ ±í´ïʽ¡£
WHEN when_expression
ʹÓüòµ¥ CASE ¸ñʽʱ input_expression Ëù±È½ÏµÄ¼òµ¥±í´ïʽ¡£When_expression ÊÇÈÎÒâÓÐЧµÄ SQL Server ±í´ïʽ¡£Input_expression ºÍÿ¸ö when_expression µÄÊý¾ÝÀàÐͱØÐëÏàͬ£¬»òÕßÊÇÒþÐÔת»»¡£
n
ռλ·û£¬±íÃ÷¿ÉÒÔʹÓöà¸ö WHEN when_expression THEN result_expression ×Ó¾ä»ò WHEN Boolean_expression THEN result_expression ×Ӿ䡣
THEN result_expression
µ± input_expression = when_expression ȡֵΪ TRUE£¬»òÕß Boolean_expression ȡֵΪ TRUE ʱ·µ»ØµÄ±í´ïʽ¡£result expression ÊÇÈÎÒâÓÐЧµÄ SQL Server ±í´ïʽ¡£
ELSE else_result_expression
µ±±È½ÏÔËËãÈ¡Öµ²»Îª TRUE ʱ·µ»ØµÄ±í´ïʽ¡£Èç¹ûÊ¡ÂԴ˲ÎÊý²¢ÇұȽÏÔËËãÈ¡Öµ²»Îª TRUE£¬CASE ½«·µ»Ø NULL Öµ¡£Else_result_expression ÊÇÈÎÒâÓÐЧµÄ SQL Server ±í´ïʽ¡£Else_result_expression ºÍËùÓÐ result_expression µÄÊý¾ÝÀàÐͱØÐëÏàͬ£¬»òÕß±ØÐëÊÇÒþÐÔת»»¡£
WHEN Boolean_expression
ʹÓà CASE ËÑË÷¸ñʽʱËù¼ÆËãµÄ²¼¶û±í´ïʽ¡£Boolean_expression ÊÇÈÎÒâÓÐЧµÄ²¼¶û±í´ïʽ¡£
½á¹ûÀàÐÍ
´Ó result_expressions ºÍ¿ÉÑ¡ else_result_expression µÄÀàÐͼ¯ºÏÖзµ»Ø×î¸ßµÄÓÅÏȹæÔòÀàÐÍ¡£Óйظü¶àÐÅÏ¢£¬Çë²Î¼ûÊý¾ÝÀàÐ͵ÄÓÅÏÈ˳Ðò¡£
½á¹ûÖµ
¼òµ¥ CASE º¯Êý£º


Ïà¹ØÎĵµ£º

º½¿Õ¹«Ë¾¹ÜÀíϵͳ(VC++ ÓëSQL 2005)

ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
      ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......

SQL CREATE VIEWµÄÓ÷¨

ÊÓ¹Û±í (Views) ¿ÉÒÔ±»µ±×÷ÊÇÐéÄâ±í¸ñ¡£Ëü¸ú±í¸ñµÄ²»Í¬ÊÇ£¬±í¸ñÖÐÓÐʵ¼Ê´¢´æ×ÊÁÏ£¬¶øÊÓ¹Û±íÊǽ¨Á¢ÔÚ±í¸ñÖ®ÉϵÄÒ»¸ö¼Ü¹¹£¬Ëü±¾Éí²¢²»Êµ¼Ê´¢´æ×ÊÁÏ¡£
½¨Á¢Ò»¸öÊÓ¹Û±íµÄÓï·¨ÈçÏ£º
CREATE VIEW "VIEW_NAME" AS "SQL Óï¾ä"
"SQL Óï¾ä" ¿ÉÒÔÊÇÈκÎÒ»¸öÎÒÃÇÔÚÕâ¸ö½Ì²ÄÖÐÓÐÌáµ½µÄ SQL¡£
À´¿´Ò»¸öÀý×Ó¡£¼ÙÉèÎÒÃÇÓÐÒÔϵıí¸ñ£ ......

SQL ALTER TABLEµÄÓ÷¨

ÔÚ±í¸ñ±»½¨Á¢ÔÚ×ÊÁÏ¿âÖкó£¬ÎÒÃdz£³£»á·¢ÏÖ£¬Õâ¸ö±í¸ñµÄ½á¹¹ÐèÒªÓÐËù¸Ä±ä¡£³£¼ûµÄ¸Ä±äÈçÏ£º
¼ÓÒ»¸öÀ¸Î»
ɾȥһ¸öÀ¸Î»
¸Ä±äÀ¸Î»Ãû³Æ
¸Ä±äÀ¸Î»µÄ×ÊÁÏÖÖÀà
ÒÔÉÏÁгöµÄ¸Ä±ä²¢²»ÊÇËùÓпÉÄܵĸı䡣ALTER TABLE Ò²¿ÉÒÔ±»ÓÃÀ´×÷ÆäËûµÄ¸Ä±ä£¬ÀýÈç¸Ä±äÖ÷¼ü¶¨Òå¡£
ALTER TABLE µÄÓï·¨ÈçÏ£º
ALTER TABLE "table_name" ......

SQL DROP TABLEµÄÓ÷¨

ÓÐʱºòÎÒÃÇ»á¾ö¶¨ÎÒÃÇÐèÒª´ÓÊý¾Ý¿âÖÐÇå³ýÒ»¸ö±í¸ñ¡£ÊÂʵÉÏ£¬Èç¹ûÎÒÃDz»ÄÜÕâÑù×öµÄ»°£¬Äǽ«»áÊÇÒ»¸öºÜ´óµÄÎÊÌ⣬ÒòΪÊý¾Ý¿â¹ÜÀíʦ (Database Administrator -- DBA) ÊƱØÎÞ·¨¶ÔÊý¾Ý¿â×öÓÐЧÂʵĹÜÀí¡£»¹ºÃ£¬SQL ÓÐÌṩһ¸ö DROP TABLEµÄÓï·¨À´ÈÃÎÒÃÇÇå³ý±í¸ñ¡£ DROP TABLE µÄÓï·¨ÊÇ£º
DROP TABLE "±í¸ñÃû"
ÎÒÃÇÈç¹ûÒªÇå³ ......

asp.net·Àsql×¢Èë

 using (con)
        {
            con.Open();
            String sqltext = "select * from emp where empno=@empno";
      ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ