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

SQLÖÐ ³£ÓõĴ¦Àí·½·¨

 -- Ò»£º ´¦Àíδ²éµ½µÄ¿ÕÖµ
 select
 case when exists(select EndPrice from T_stock where BOMSN='0109')
 then (select EndPrice from T_stock where BOMSN='0109')
 else 0 end
 --¶þ£º¸üÐÂ×Ö¶ÎÖµ
 --strNum ÊýÁ¿
 --strId  ÐòºÅ
 update T_buy_Pro set CompentNum=isnull(CompentNum,0)+'strNum' ,
 Status= case when isnull(BuyNumber,0) > isnull(CompentNum,0)+ 'strNum'
 then '²¿·ÖÊÕÁÏ' else 'È«²¿ÊÕÁÏ' end
 where BuyProID='strId'
È¥µôСÊýµãÓÐЧÊý×ÖºóÃæµÄËùÓÐ0
decimalÀàÐÍ£¬Ð¡ÊýλÊýÊÇ6룬Èç¹û²åÈëµÄÊý¾ÝΪ2.5£¬Ôò¼ìË÷ʱÏÔʾΪ2.500000
select   cast(2.500000       as     real)
----------½¨Ò»個º¯數Íê³É-------------   
  Create     Function     trun(@i     decimal(18,6))   
  returns       varchar(30)   
  begin     
  declare     @s     varchar(30)   
  set     @s=cast(@i     as   varchar(30))   
  while   len(@s)>0   
  begin           
            if   cast(substring(rtrim(@s),len(rtrim(@s))-1,1)     as     int)<>0         
            begin   
                    set     @s=substring(rtrim(@s),1,len(@s)-1)   
                    break   
            end   
            set     @s=substring(rtrim(@s),1,len(@s)-1)   
  end   
        return(@s)   
  end   
  ----------------------------結Êøº¯數--------


Ïà¹ØÎĵµ£º

SQL ½«ÁÐת»»ÎªÐУ¬Ï൱ÓÚ½«±í½á¹¹Ðýת90¶È

½«ÁÐת»»ÎªÐУ¬Ï൱ÓÚ½«±í½á¹¹Ðýת90¶È
T_Student ±í
Stud_ID
Sex
Name
1
ÄÐ
Tom
2
Å®
Anne
3
ÄÐ
Jack
 
Ö´ÐÐ: Exec proColumnToRow ’T_Student’,’Name’,’ New_ID’
 
ת»»ºóµÄ±í
 
New_ID
Tom
Anne
Jack
Stud_ID
1
2
3
Sex
ÄÐ
Å®
ÄÐ
& ......

SQLÖÐ groupbyºÍhavingµÄÇø±ð

½éÉÜGROUP BY ºÍ HAVING ×Ó¾äǰ£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý:¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
 SELECT SUM(population) from bbc
ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéѯֻ·µ»ØÒ»¸ö½á¹û£¬¼´ËùÓйú¼ÒµÄ×ÜÈË¿ ......

Sqlʱ¼ä¸ñʽ»¯·½·¨(ת)


Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select
CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100),
GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3):
16/05/06
Select CONVERT(varchar(100), GETDATE(), 4): 16.05.06
Select
CON ......

sqlÖØ¸´Êý¾Ý´¦Àí£¬ÓÐΨһID£¬formidÓÐÖØ¸´,ÁôÒ»Ìõ

/*sqlÖØ¸´Êý¾Ý´¦Àí£¬ÓÐΨһID£¬formidÓÐÖØ¸´*/
/*²é³öÖØ¸´µÄfromid*/
select formid from GaiaSaver_BUG group by formid having count(*)>1
/*ɾ³ýÖØ¸´formid£¬Ö»ÁôÒ»Ìõ*/
delete from GaiaSaver_BUG  where ID not in
(select   min(ID) as ID  from  GaiaSaver_BUG  group by for ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ