ת×Ôhttp://lavasoft.blog.51cto.com/62575/23373
SQLÓïÑÔµÄCASEÓï¾ä±¸Íü
¸ÅÊö£º
SQLÓï¾äÖеÄCASEÓï¾äÓë¸ß¼¶ÓïÑÔÖеÄswitchÓï¾ä£¬ÊDZê×¼SQLµÄÓï·¨£¬ÊÊÓÃÓëÒ»¸öÌõ¼þÅжÏÓжàÖÖÖµµÄÇé¿öÏ·ֱðÖ´Ðв»Í¬µÄ²Ù×÷¡£Áé»îÓ¦ÓÃCASEÓï¾ä¿ÉÒÔʹSQLÓï¾ä±äµÃ¼ò½àÒ×¶Á£¬ÏÂÃæÔÚDB2»·¾³ÏÂͨ¹ýÒ»¸ö¼òµ¥µÄ²éѯÀ´Õ¹Ê¾SQL CASEÓï¾äµÄÇ¿´ó¹¦ÄÜ¡£
»·¾³£º
Windows XP Professional
DB2 V9.1
ÎÊÌ⣺
ÓÐÒ»¸öÐÐÒµ´úÂë±í£¬½¨±íSQLºÍÊý¾ÝÈçÏ£¬ÒªÇó²é³ö´úÂë±ðÃû¡¢´úÂëÃû¡¢ÐÐÒµÃû¡¢´úÂ볤¶È¡£´úÂë±ðÃûΪÊý×ÖÐòºÅÓë´óдӢÎÄ×ÖĸµÄÐòºÅµÄÓ³ÉäÖµ£¬±ÈÈç´úÂë '01'µÄ±ðÃû¾ÍÊÇ'A','02'µÄ±ðÃû¾ÍÊÇ'B',ÒÀ´ÎÀàÍÆ¡£
½¨±íSQLºÍ³õʼ»¯Êý¾ÝSQL
-------------------------------------
drop table DM_HYML;
create table DM_HYML
(
HYML_DM CHAR(2) not null,
HYML_MC VARCHAR(100) not null,
XYBZ CHAR(1) not null
);
alter table DM_HYML
add primary key (HYML_DM);
comment on table DM_HYML is
'ÐÐÒµÃÅÀà´úÂë±í';
comment on column DM_HYML.HYML_DM is
'ÐÐÒµÃÅÀà´úÂë';
comment on column DM_HYML.HYML_MC is
'ÐÐÒµÃÅÀàÃû³Æ';
comment on column DM_HYML.XYBZ is
'Ñ¡ÓñêÖ¾';
delete from DM_HYML;
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('01', 'Å©¡¢ÁÖ¡¢ÄÁ¡¢ÓæÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('03', 'ÖÆÔìÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('02', '²É¿óÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('04', 'µçÁ¦¡¢È¼Æø¼°Ë®µÄÉú²úºÍ¹©Ó¦Òµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('05', '½¨ÖþÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('06', '½»Í¨ÔËÊä¡¢²Ö´¢ºÍÓÊÕþÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('07', 'ÐÅÏ¢´«Êä¡¢¼ÆËã»ú·þÎñºÍÈí¼þÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('08', 'Åú·¢ºÍÁãÊÛÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)
values ('09', 'סË޺ͲÍÒûÒµ', 'Y');
insert into DM_HYML (HYML_DM, HYML_MC, XYBZ)