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

SQLÁ÷Ë®ºÅÉú³ÉÓï¾ä

table
     
        Num        createDate
---------------------------------
      (¿Õ)          20090901
      (¿Õ)          20090901
      (¿Õ)          20090902
      (¿Õ)          20090902
      (¿Õ)          20090903
      (¿Õ)          20090903
---------------------------------
      ÏÖÔÚҪͨ¹ýcreateDateÀ´²úÉúÒ»¸öÁ÷Ë®ºÅ(4λ) °´µ±ÌìÀ´Éú³É »»ÌìÒªÖØÐÂÉú³É
      ¼´µÃµ½½á¹ûÈçÏÂ:
table
     
        Num        createDate
---------------------------------
    200909010001    20090901
    200909010002    20090901           
    200909020001    20090902
    200909020002    20090902
    200909030001    20090903
    200909030002    20090903
---------------------------------
create table tb(id int , Num varchar(12),createDate varchar(8))
insert into tb values(1,'','20090901')
insert into tb values(2,'','20090901')
insert into tb values(3,'','20090902')
insert into tb values(4,'','20090902')
insert into tb values(5,'','20090903')
insert into tb values(6,'','20090903')
go
update tb set num = createDate + right('000'+cast((select count(1) from tb where createDate = t.createDate and id < t.id) + 1 as varchar),4) from tb t
select * from tb
drop table tb
/*
id          Num          createDate
----------- ------------ ----------
1           200909010001 2009


Ïà¹ØÎĵµ£º

SQLÖÐÈçºÎÕýÈ·ÈÏʶ´¥·¢Æ÷

¶ÔÓÚ³õѧÕ߶Դ¥·¢Æ÷µÄÀí½âÍùÍù²»ÊǺÜ͸³¹£¬¼ÇµÃ×Ô¼ºµ±³õѧµÄʱºò×ÜÓеãÃþ²»ÇåÍ·ÄԵĸоõ£¬½ñÌì¾ÍÏëÆðºÍ´ó¼Ò×ܽáһϣ¬Èç¹ûÎÄÕ³öÏÖЩ覴ÃÇë¸ßÊÖ¶à¶àÖ¸½ÌŶ£¡
´¥·¢Æ÷ÊÇÊý¾Ý¿â·þÎñÆ÷Öз¢Éúʼþʱ×Ô¶¯Ö´ÐеÄÌØÊâ´æ´¢¹ý³Ì£¬Ëü²åÈ롢ɾ³ý»òÐÞ¸ÄÌرíÖеÄÊý¾Ýʱ´¥·¢Ö´ÐС£´¥·¢Æ÷ͨ³£¿ÉÒÔÇ¿ÖÆÖ´ÐÐÒ»¶¨µÄÒµÎñ¹æÔò£¬ÒÔ±£³ÖÊý¾ÝÍêÕûÐÔ ......

ms sql dateimeÖ®1905

 ÔÚ×ö“¶¼ÊмÒÔ°”ÓÅ»¯Ê±£¬¾ßÌåÊÇÓû§×¢²áʱ£¬Ìá½»ÐÅÏ¢£¬±¾À´BirthdayÊÇûÓÐдÈëÖµµÄ£¬´Ë×Ö¶ÎҲûÓÐĬÈÏÖµ£¬¿ÉÊý¾Ý¿âÖÐȴΪ“1905/3/14 0:00:00”£¬ÓôÃÆÖÁ¼«£¬ÉÏgoogle&baiduÒ²ÊÇûÓнâ¾öµÄ·½°¸¡£
Ö»ÄÜÕâÑùԭʼµÄ½â¾ö£º
Register ´æ´¢¹ý³Ì
   insert into UserInfo(UserID,sex) ......

SQL ServerʵÏÖÊý¾Ý¿â¶¨Ê±×Ô¶¯±¸·Ý

ÔÚSQL ServerÖгöÓÚÊý¾Ý°²È«µÄ¿¼ÂÇ£¬ËùÒÔÐèÒª¶¨Æڵı¸·ÝÊý¾Ý¿â¡£¶ø±¸·ÝÊý¾Ý¿âÒ»°ãÓÖÊÇÔÚÁ賿ʱ¼ä»ù±¾Ã»ÓÐÊý¾Ý¿â²Ù×÷µÄʱºò½øÐУ¬ËùÒÔÎÒÃDz»¿ÉÄÜÒªÇó¹ÜÀíԱÿÌìÊص½ÍíÉÏ1µãÈ¥±¸·ÝÊý¾Ý¿â¡£ÒªÊµÏÖÊý¾Ý¿âµÄ¶¨Ê±×Ô¶¯±¸·Ý£¬×î³£Óõķ½Ê½¾ÍÊÇʹÓÃSQL Server´úÀíÖеÄ×÷Òµ¡£Æô¶¯SQL Server Agent·þÎñ£¬È»ºóÔÚÆäÖÐн¨×÷Òµ£¬×÷ÒµÖÐÌí¼ ......

SQLÏ°Ìâ2

 µÚʮһÌ⣺
Óбístudents(name,class,grade),ÇëÓñê×¼sqlÓï¾äÍê³É
name class grade
ÕÅÈý Êýѧ 81
ÀîËÄ ÓïÎÄ 70
ÍõÎå Êýѧ 90
ÕÅÈý ÓïÎÄ 60
ÀîËÄ Êýѧ 100
ÍõÎå ÓïÎÄ 90
ÍõÎå Ó¢Óï 81
ÒªÇó: ÓÃsqlÓï¾äÊä³ö¸÷ÃŹ¦¿Î¶¼´óÓÚ80·ÖµÄͬѧÐÕÃû?
create table students (
name varchar(25),
class varchar(25), ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ