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
----------------------------結Êøº¯數--------
Ïà¹ØÎĵµ£º
USE master
GO
DECLARE @dbname sysname
SET @dbname='TEST' --Õâ¸öÊÇҪɾ³ýµÄÊý¾Ý¿â¿âÃû
DECLARE @s NVARCHAR(1000)
DECLARE tb CURSOR local FOR
SELECT s='KILL '+CAST(spid AS NVARCHAR)&nbs ......
±¾ÎÄ´ÓÊý¾Ý¿âÉè¼Æ¡¢¿ª·¢¡¢DBA¹ÜÀíµÈËĸö·½ÃæÐðÊöÁËSQL2005ÓëSQL2000Á½¸ö°æ±¾¼äµÄ¸Ä½ø¡£
¡¡¡¡Ò»¡¢Êý¾Ý¿âÉè¼Æ·½Ãæ
¡¡
¡¡1¡¢×Ö¶ÎÀàÐÍ¡£
¡¡¡¡varchar(max)
varchar(max)ÀàÐ͵ÄÒýÈë´ó´óµÄÌá¸ßÁ˱à³ÌµÄЧÂÊ£¬¿ÉÒÔʹÓÃ×Ö·û´®º¯Êý¶ÔCLOBÀàÐͽøÐвÙ×÷£¬ÕâÊÇÒ»¸öÁÁµã¡£µ«ÊÇÕâ¾ÍÒý·¢Á˶Ôvarchar
ºÍcharЧÂÊÌÖÂÛµÄÀÏÎÊÌâ¡£µ½µ ......
½éÉÜGROUP BY ºÍ HAVING ×Ó¾äǰ£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý:¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
SELECT SUM(population) from bbc
ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéѯֻ·µ»ØÒ»¸ö½á¹û£¬¼´ËùÓйú¼ÒµÄ×ÜÈË¿ ......
ÈçºÎʵÏÖ¶à¸ö¹Ø¼ü×Ö°´ÕÕ²»Í¬ÅÅÐò¹æÔò½øÐÐÅÅÐòÄØ£¿
ORDER BY×Ó¾äÈÃÊý¾Ý¿â¶Ô²éѯ½á¹ûÅÅÐò£¬ORDER BY×Ӿ䱨Ðë·ÅÔÚ²éѯÓï¾äµÄ½áβ¡£Æä»ù±¾ÓÃ
·¨ÈçÏ£º
SELECT * from Contacts ORDER BY first_name;
Äã¿ÉÒÔ¶Ô¶àÁÐÊý¾ÝÅÅÐò¡£ÓÅÏÈ˳Ðò°´´Ó×óµ½ÓÒÒÀ´Î½µµÍ£¬ËùÒÔ²éѯÓï¾äÖ ......
/*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 ......