SQLÖ® case when then
ÊÓͼ²éѯÖÐÔõÑù½«Ô¶¨ÓÚÈçÐÔ±ðsex ÕâÑùµÄ×ֶΣ¬×Ö¶ÎֵΪ0£¬1ÕâÑùµÄintÀàÐÍÖµ£¬²éѯʱֱ½Ó·µ»Øvarchar
Ð͵Ä×Ö·û‘ÄÐ’£¬‘Å®’ÒÔ±ãÓÚÎÒÃǶÁÈ¡ÄØ£¿
ÓÐÈË»áÏëµ½if …else…ÕâÑùµÄÓï¾ä£¬¿ÉÊÇÔõô¼Ó£¬¶¼²»ÖªµÀ¼ÓÄÄÀÒòΪ×ÜÊÇ»á³ö´í¡£ÆäʵsqlÖÐÓÐÒ»¸öº¯ÊýÄܽâ¾öÕâÑùµÄ²éѯ¶ÁÈ¡ÖµµÄÎÊÌâ¡£ÄǾÍÊÇÏÂ
ÃæÒª½éÉÜµÄ Case º¯ÊýÁË¡£
Case ÊǼÆËãÌõ¼þÁÐ±í²¢·µ»Ø¶à¸ö¿ÉÄܵĽá¹û±í´ïʽ֮һ¡£
Case ÓÐÁ½ÖÖ¸ñʽ£º
¼òµ¥ Case º¯Êý½«Ä³¸ö±í´ïʽÓëÒ»×é¼òµ¥±í´ïʽ½øÐбȽÏÒÔÈ·¶¨½á¹û¡£
Case ËÑË÷º¯Êý¼ÆËãÒ»×é²¼¶û±í´ïʽÒÔÈ·
¶¨½á¹û¡£
Á½ÖÖ¸ñʽ¾ùÖ§³Ö¿ÉÑ¡µÄ ELSE ²ÎÊý¡£
Óï·¨
1. CASE
input_expression
WHEN
when_expression
THEN
result_expression
[
...n
] [ELSE else_result_expression
] END
2. CASE
WHEN
Boolean_expression
THEN
result_expression
[ ...n
] [
ELSE else_result_expression
] END
Àý×Ó
1.Ó﷨ʵÀý£º
SELECT Name,Age,CASE Gender WHEN 1 THEN 'Å®' WHEN 2 THEN 'ÄÐ' ELSE
'δÌî' END AS Genders from dbo.Contacter_Detail
2. Ó﷨ʵÀý£º
SELECT Name,Age,CASE WHEN Gender = 1 THEN 'Å®' WHEN .Gender = 2
THEN 'ÄÐ' ELSE 'δÌî' END AS Genders,
from dbo.Contacter_Detail
Á½Õß·µ»ØµÄ½á¹ûÊÇÒ»Ñù¡£ºÜ¼òµ¥£¬Ò»¶¨¼ÇסºóÃæ±í´ïʽºóÃæÓиöEND½áβÄØ£¡
Ïà¹ØÎĵµ£º
1.ͨ¹ý¹¤¾ßDTSµÄÉè¼ÆÆ÷½øÐе¼Èë»òµ¼³ö
DTSµÄÉè¼ÆÆ÷¹¦ÄÜÇ¿´ó£¬Ö§³Ö¶àÈÎÎñ£¬Ò²ÊÇ¿ÉÊÓ»¯½çÃ棬ÈÝÒײÙ×÷£¬µ«ÖªµÀµÄÈËÒ»°ã²»¶à£¬Èç¹ûÖ»ÊǽøÐÐSQL ServerÊý¾Ý¿âÖв¿·Ö±íµÄÒƶ¯£¬ÓÃÕâÖÖ·½·¨×îºÃ£¬µ±È»£¬Ò²¿ÉÒÔ½øÐÐÈ«²¿±íµÄÒƶ¯¡£ÔÚSQL Server Enterprise ManagerÖУ¬Õ¹¿ª·þÎñÆ÷×ó±ßµÄ+£¬Ñ¡ÔñÊý¾Ý¿â£¬ÓÒ»÷£¬Ñ¡ÔñAll tasks/Import ......
ת×Ô£ºhttp://news.newhua.com/news1/program_database/2008/530/0853093226E2KJ93C02415FEB1CD9A5HCKA821556279EEKJ7728GI5.html
ÊÂÎñÈÕÖ¾ÎļþTransaction Log FileÊÇÓÃÀ´¼Ç¼Êý¾Ý¿â¸üÐÂÇé¿öµÄÎļþ£¬À©Õ¹ÃûΪldf¡£
ÔÚ SQL Server 7.0 ºÍ SQL Server 2000 ÖУ¬Èç¹ûÉèÖÃÁË×Ô¶¯Ôö³¤¹¦ÄÜ£¬ÊÂÎñÈÕÖ¾Îļþ½«»á×Ô¶¯À©Õ¹¡£
Ò»° ......
--> Title : ijÍâÆóSQL ServerÃæ試題
--> Author : wufeng4552
--> Date : 2010-1-15
Question 1£ºCan you use a batch SQL or store procedure to calculating the Number of Days in a Month
Answer 1£ºÕÒ³öµ±ÔµÄÌìÊý
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast( ......
C = CHECK Ô¼Êø
D = ĬÈÏÖµ»ò DEFAULT Ô¼Êø
F = FOREIGN KEY Ô¼Êø
FN = ±êÁ¿º¯Êý
IF = ÄÚǶ±íº¯Êý
K = PRIMARY KEY »ò UNIQUE Ô¼Êø
L = ÈÕÖ¾
P = ´æ´¢¹ý³Ì
R = ¹æÔò
RF = ¸´ÖÆɸѡ´æ´¢¹ý³Ì
S = ϵͳ±í
TF = ±íº¯Êý
TR = ´¥·¢Æ÷
U = Óû§±í
V = ÊÓͼ
X = À©Õ¹´æ´¢¹ý³Ì
......
OracleÓкܶàÖµµÃѧϰµÄµØ·½£¬ÕâÀïÎÒÃÇÖ÷Òª½éÉÜOracle UNION ALL£¬°üÀ¨½éÉÜUNIONµÈ·½Ã档ͨ³£Çé¿öÏ£¬ÓÃUNIONÌæ»»WHERE×Ó¾äÖеÄOR½«»áÆ𵽽ϺõÄЧ¹û¡£¶ÔË÷ÒýÁÐʹÓÃOR½«Ôì³ÉÈ«±íɨÃè¡£×¢Ò⣬ÒÔÉϹæÔòÖ»Õë¶Ô¶à¸öË÷ÒýÁÐÓÐЧ¡£¼ÙÈçÓÐcolumnûÓб»Ë÷Òý£¬²éѯЧÂÊ¿ÉÄÜ»áÒòΪÄúûÓÐÑ¡ÔñOR¶ø½µµÍ¡£ÔÚÏÂÃæµÄÀý×ÓÖУ¬LOC_ID ºÍREGION ......